Use common implementation of fastLog2 based on countLeadingZeroBits

This commit is contained in:
Ilya Gorbunov
2019-06-20 20:56:56 +03:00
parent f8724654a1
commit 39bdf34b9f
3 changed files with 3 additions and 15 deletions
+3 -1
View File
@@ -336,9 +336,11 @@ public fun Random.nextLong(range: LongRange): Long = when {
internal expect fun defaultPlatformRandom(): Random
internal expect fun fastLog2(value: Int): Int // 31 - Integer.numberOfLeadingZeros(value)
internal expect fun doubleFromParts(hi26: Int, low27: Int): Double
@UseExperimental(ExperimentalStdlibApi::class)
internal fun fastLog2(value: Int): Int = 31 - value.countLeadingZeroBits()
/** Takes upper [bitCount] bits (0..32) from this number. */
internal fun Int.takeUpperBits(bitCount: Int): Int =
this.ushr(32 - bitCount) and (-bitCount).shr(31)