[stdlib] Further merge js-ir specific sources

This commit is contained in:
Ilya Gorbunov
2023-10-08 00:20:24 +02:00
committed by Space Team
parent 911fa3bbbb
commit aedc704e77
6 changed files with 78 additions and 94 deletions
@@ -38,6 +38,63 @@ public actual fun Double.isFinite(): Boolean = !isInfinite() && !isNaN()
public actual fun Float.isFinite(): Boolean = !isInfinite() && !isNaN()
/**
* Returns a bit representation of the specified floating-point value as [Long]
* according to the IEEE 754 floating-point "double format" bit layout.
*/
@SinceKotlin("1.2")
public actual fun Double.toBits(): Long =
doubleToRawBits(if (this.isNaN()) Double.NaN else this)
/**
* Returns a bit representation of the specified floating-point value as [Long]
* according to the IEEE 754 floating-point "double format" bit layout,
* preserving `NaN` values exact layout.
*/
@SinceKotlin("1.2")
public actual fun Double.toRawBits(): Long =
doubleToRawBits(this)
/**
* Returns the [Double] value corresponding to a given bit representation.
*/
@SinceKotlin("1.2")
@kotlin.internal.InlineOnly
public actual inline fun Double.Companion.fromBits(bits: Long): Double =
doubleFromBits(bits)
/**
* Returns a bit representation of the specified floating-point value as [Int]
* according to the IEEE 754 floating-point "single format" bit layout.
*
* Note that in Kotlin/JS [Float] range is wider than "single format" bit layout can represent,
* so some [Float] values may overflow, underflow or loose their accuracy after conversion to bits and back.
*/
@SinceKotlin("1.2")
public actual fun Float.toBits(): Int =
floatToRawBits(if (this.isNaN()) Float.NaN else this)
/**
* Returns a bit representation of the specified floating-point value as [Int]
* according to the IEEE 754 floating-point "single format" bit layout,
* preserving `NaN` values exact layout.
*
* Note that in Kotlin/JS [Float] range is wider than "single format" bit layout can represent,
* so some [Float] values may overflow, underflow or loose their accuracy after conversion to bits and back.
*/
@SinceKotlin("1.2")
public actual fun Float.toRawBits(): Int =
floatToRawBits(this)
/**
* Returns the [Float] value corresponding to a given bit representation.
*/
@SinceKotlin("1.2")
@kotlin.internal.InlineOnly
public actual inline fun Float.Companion.fromBits(bits: Int): Float =
floatFromBits(bits)
/**
* Counts the number of set bits in the binary representation of this [Int] number.
*/
+12
View File
@@ -448,6 +448,18 @@ public actual inline val Double.absoluteValue: Double get() = nativeMath.abs(thi
@InlineOnly
public actual inline val Double.sign: Double get() = nativeSign(this)
/**
* Returns this value with the sign bit same as of the [sign] value.
*
* If [sign] is `NaN` the sign of the result is undefined.
*/
@SinceKotlin("1.2")
public actual fun Double.withSign(sign: Double): Double {
val thisSignBit = doubleSignBit(this)
val newSignBit = doubleSignBit(sign)
return if (thisSignBit == newSignBit) this else -this
}
/**
* Returns this value with the sign bit same as of the [sign] value.
*/
@@ -1,17 +0,0 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package kotlin.math
/**
* Returns this value with the sign bit same as of the [sign] value.
*
* If [sign] is `NaN` the sign of the result is undefined.
*/
@SinceKotlin("1.2")
public actual fun Double.withSign(sign: Double): Double {
val thisSignBit = doubleSignBit(this)
val newSignBit = doubleSignBit(sign)
return if (thisSignBit == newSignBit) this else -this
}
@@ -1,62 +0,0 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package kotlin
/**
* Returns a bit representation of the specified floating-point value as [Long]
* according to the IEEE 754 floating-point "double format" bit layout.
*/
@SinceKotlin("1.2")
public actual fun Double.toBits(): Long =
doubleToRawBits(if (this.isNaN()) Double.NaN else this)
/**
* Returns a bit representation of the specified floating-point value as [Long]
* according to the IEEE 754 floating-point "double format" bit layout,
* preserving `NaN` values exact layout.
*/
@SinceKotlin("1.2")
public actual fun Double.toRawBits(): Long =
doubleToRawBits(this)
/**
* Returns the [Double] value corresponding to a given bit representation.
*/
@SinceKotlin("1.2")
@kotlin.internal.InlineOnly
public actual inline fun Double.Companion.fromBits(bits: Long): Double =
doubleFromBits(bits)
/**
* Returns a bit representation of the specified floating-point value as [Int]
* according to the IEEE 754 floating-point "single format" bit layout.
*
* Note that in Kotlin/JS [Float] range is wider than "single format" bit layout can represent,
* so some [Float] values may overflow, underflow or loose their accuracy after conversion to bits and back.
*/
@SinceKotlin("1.2")
public actual fun Float.toBits(): Int =
floatToRawBits(if (this.isNaN()) Float.NaN else this)
/**
* Returns a bit representation of the specified floating-point value as [Int]
* according to the IEEE 754 floating-point "single format" bit layout,
* preserving `NaN` values exact layout.
*
* Note that in Kotlin/JS [Float] range is wider than "single format" bit layout can represent,
* so some [Float] values may overflow, underflow or loose their accuracy after conversion to bits and back.
*/
@SinceKotlin("1.2")
public actual fun Float.toRawBits(): Int =
floatToRawBits(this)
/**
* Returns the [Float] value corresponding to a given bit representation.
*/
@SinceKotlin("1.2")
@kotlin.internal.InlineOnly
public actual inline fun Float.Companion.fromBits(bits: Int): Float =
floatFromBits(bits)
@@ -124,6 +124,15 @@ public actual inline fun Short.toString(radix: Int): String = this.toInt().toStr
@SinceKotlin("1.2")
public actual fun Int.toString(radix: Int): String = asDynamic().toString(checkRadix(radix))
/**
* Returns a string representation of this [Long] value in the specified [radix].
*
* @throws IllegalArgumentException when [radix] is not a valid radix for number to string conversion.
*/
@SinceKotlin("1.2")
public actual fun Long.toString(radix: Int): String =
this.toStringImpl(checkRadix(radix))
private fun String.isNaN(): Boolean = when (this.lowercase()) {
"nan", "+nan", "-nan" -> true
else -> false
@@ -1,15 +0,0 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package kotlin.text
/**
* Returns a string representation of this [Long] value in the specified [radix].
*
* @throws IllegalArgumentException when [radix] is not a valid radix for number to string conversion.
*/
@SinceKotlin("1.2")
public actual fun Long.toString(radix: Int): String =
this.toStringImpl(checkRadix(radix))