Bit query and bit rotation functions for Int, Long, Short, Byte
#KT-12749
This commit is contained in:
@@ -230,6 +230,17 @@ if (typeof Math.log2 === "undefined") {
|
||||
return Math.log(x) * Math.LOG2E;
|
||||
};
|
||||
}
|
||||
if (typeof Math.clz32 === "undefined") {
|
||||
Math.clz32 = (function(log, LN2) {
|
||||
return function(x) {
|
||||
var asUint = x >>> 0;
|
||||
if (asUint === 0) {
|
||||
return 32;
|
||||
}
|
||||
return 31 - (log(asUint) / LN2 | 0) | 0; // the "| 0" acts like math.floor
|
||||
};
|
||||
})(Math.log, Math.LN2);
|
||||
}
|
||||
|
||||
// For HtmlUnit and PhantomJs
|
||||
if (typeof ArrayBuffer.isView === "undefined") {
|
||||
|
||||
@@ -58,4 +58,9 @@ public actual fun Float.toRawBits(): Int = definedExternally
|
||||
*/
|
||||
@SinceKotlin("1.2")
|
||||
@kotlin.internal.InlineOnly
|
||||
public actual inline fun Float.Companion.fromBits(bits: Int): Float = js("Kotlin").floatFromBits(bits).unsafeCast<Float>()
|
||||
public actual inline fun Float.Companion.fromBits(bits: Int): Float = js("Kotlin").floatFromBits(bits).unsafeCast<Float>()
|
||||
|
||||
|
||||
internal inline fun Long(low: Int, high: Int) = js("Kotlin").Long.fromBits(low, high).unsafeCast<Long>()
|
||||
internal inline val Long.low: Int get() = this.asDynamic().getLowBits().unsafeCast<Int>()
|
||||
internal inline val Long.high: Int get() = this.asDynamic().getHighBits().unsafeCast<Int>()
|
||||
Reference in New Issue
Block a user