More efficient double generation in JS
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
|
||||
package kotlin.random
|
||||
|
||||
import kotlin.math.pow
|
||||
|
||||
internal actual fun defaultPlatformRandom(): Random =
|
||||
Random(js("(Math.random() * Math.pow(2, 32)) | 0").unsafeCast<Int>())
|
||||
|
||||
@@ -18,4 +20,9 @@ internal actual fun fastLog2(value: Int): Int {
|
||||
log++
|
||||
}
|
||||
return log
|
||||
}
|
||||
}
|
||||
|
||||
private val INV_2_26: Double = 2.0.pow(-26)
|
||||
private val INV_2_53: Double = 2.0.pow(-53)
|
||||
internal actual fun doubleFromParts(hi26: Int, low27: Int): Double =
|
||||
hi26 * INV_2_26 + low27 * INV_2_53
|
||||
Reference in New Issue
Block a user