Hide deprecated JS Math object from public API and rename to JsMath
KT-41318 - Rename Math to JsMath and remove unused functions - Fix return types, remove duplicating JsMath from longjs.kt Co-authored-by: Abduqodiri Qurbonzoda <abduqodiri.qurbonzoda@jetbrains.com>
This commit is contained in:
@@ -27,9 +27,8 @@ public actual fun <T : Comparable<T>> maxOf(a: T, b: T): T {
|
||||
*/
|
||||
@SinceKotlin("1.1")
|
||||
@kotlin.internal.InlineOnly
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
public actual inline fun maxOf(a: Byte, b: Byte): Byte {
|
||||
return Math.max(a.toInt(), b.toInt()).unsafeCast<Byte>()
|
||||
return maxOf(a.toInt(), b.toInt()).unsafeCast<Byte>()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,9 +36,8 @@ public actual inline fun maxOf(a: Byte, b: Byte): Byte {
|
||||
*/
|
||||
@SinceKotlin("1.1")
|
||||
@kotlin.internal.InlineOnly
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
public actual inline fun maxOf(a: Short, b: Short): Short {
|
||||
return Math.max(a.toInt(), b.toInt()).unsafeCast<Short>()
|
||||
return maxOf(a.toInt(), b.toInt()).unsafeCast<Short>()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -47,16 +45,15 @@ public actual inline fun maxOf(a: Short, b: Short): Short {
|
||||
*/
|
||||
@SinceKotlin("1.1")
|
||||
@kotlin.internal.InlineOnly
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
public actual inline fun maxOf(a: Int, b: Int): Int {
|
||||
return Math.max(a, b)
|
||||
return JsMath.max(a, b)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the greater of two values.
|
||||
*/
|
||||
@SinceKotlin("1.1")
|
||||
@Suppress("DEPRECATION_ERROR", "NOTHING_TO_INLINE")
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
public actual inline fun maxOf(a: Long, b: Long): Long {
|
||||
return if (a >= b) a else b
|
||||
}
|
||||
@@ -68,9 +65,8 @@ public actual inline fun maxOf(a: Long, b: Long): Long {
|
||||
*/
|
||||
@SinceKotlin("1.1")
|
||||
@kotlin.internal.InlineOnly
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
public actual inline fun maxOf(a: Float, b: Float): Float {
|
||||
return Math.max(a, b)
|
||||
return JsMath.max(a, b)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,9 +76,8 @@ public actual inline fun maxOf(a: Float, b: Float): Float {
|
||||
*/
|
||||
@SinceKotlin("1.1")
|
||||
@kotlin.internal.InlineOnly
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
public actual inline fun maxOf(a: Double, b: Double): Double {
|
||||
return Math.max(a, b)
|
||||
return JsMath.max(a, b)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -100,9 +95,8 @@ public actual fun <T : Comparable<T>> maxOf(a: T, b: T, c: T): T {
|
||||
*/
|
||||
@SinceKotlin("1.1")
|
||||
@kotlin.internal.InlineOnly
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
public actual inline fun maxOf(a: Byte, b: Byte, c: Byte): Byte {
|
||||
return Math.max(a.toInt(), b.toInt(), c.toInt()).unsafeCast<Byte>()
|
||||
return JsMath.max(a.toInt(), b.toInt(), c.toInt()).unsafeCast<Byte>()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -110,9 +104,8 @@ public actual inline fun maxOf(a: Byte, b: Byte, c: Byte): Byte {
|
||||
*/
|
||||
@SinceKotlin("1.1")
|
||||
@kotlin.internal.InlineOnly
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
public actual inline fun maxOf(a: Short, b: Short, c: Short): Short {
|
||||
return Math.max(a.toInt(), b.toInt(), c.toInt()).unsafeCast<Short>()
|
||||
return JsMath.max(a.toInt(), b.toInt(), c.toInt()).unsafeCast<Short>()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -120,9 +113,8 @@ public actual inline fun maxOf(a: Short, b: Short, c: Short): Short {
|
||||
*/
|
||||
@SinceKotlin("1.1")
|
||||
@kotlin.internal.InlineOnly
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
public actual inline fun maxOf(a: Int, b: Int, c: Int): Int {
|
||||
return Math.max(a, b, c)
|
||||
return JsMath.max(a, b, c)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -141,9 +133,8 @@ public actual inline fun maxOf(a: Long, b: Long, c: Long): Long {
|
||||
*/
|
||||
@SinceKotlin("1.1")
|
||||
@kotlin.internal.InlineOnly
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
public actual inline fun maxOf(a: Float, b: Float, c: Float): Float {
|
||||
return Math.max(a, b, c)
|
||||
return JsMath.max(a, b, c)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -153,9 +144,8 @@ public actual inline fun maxOf(a: Float, b: Float, c: Float): Float {
|
||||
*/
|
||||
@SinceKotlin("1.1")
|
||||
@kotlin.internal.InlineOnly
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
public actual inline fun maxOf(a: Double, b: Double, c: Double): Double {
|
||||
return Math.max(a, b, c)
|
||||
return JsMath.max(a, b, c)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -249,9 +239,8 @@ public actual fun <T : Comparable<T>> minOf(a: T, b: T): T {
|
||||
*/
|
||||
@SinceKotlin("1.1")
|
||||
@kotlin.internal.InlineOnly
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
public actual inline fun minOf(a: Byte, b: Byte): Byte {
|
||||
return Math.min(a.toInt(), b.toInt()).unsafeCast<Byte>()
|
||||
return minOf(a.toInt(), b.toInt()).unsafeCast<Byte>()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -259,9 +248,8 @@ public actual inline fun minOf(a: Byte, b: Byte): Byte {
|
||||
*/
|
||||
@SinceKotlin("1.1")
|
||||
@kotlin.internal.InlineOnly
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
public actual inline fun minOf(a: Short, b: Short): Short {
|
||||
return Math.min(a.toInt(), b.toInt()).unsafeCast<Short>()
|
||||
return minOf(a.toInt(), b.toInt()).unsafeCast<Short>()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -269,16 +257,15 @@ public actual inline fun minOf(a: Short, b: Short): Short {
|
||||
*/
|
||||
@SinceKotlin("1.1")
|
||||
@kotlin.internal.InlineOnly
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
public actual inline fun minOf(a: Int, b: Int): Int {
|
||||
return Math.min(a, b)
|
||||
return JsMath.min(a, b)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the smaller of two values.
|
||||
*/
|
||||
@SinceKotlin("1.1")
|
||||
@Suppress("DEPRECATION_ERROR", "NOTHING_TO_INLINE")
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
public actual inline fun minOf(a: Long, b: Long): Long {
|
||||
return if (a <= b) a else b
|
||||
}
|
||||
@@ -290,9 +277,8 @@ public actual inline fun minOf(a: Long, b: Long): Long {
|
||||
*/
|
||||
@SinceKotlin("1.1")
|
||||
@kotlin.internal.InlineOnly
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
public actual inline fun minOf(a: Float, b: Float): Float {
|
||||
return Math.min(a, b)
|
||||
return JsMath.min(a, b)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -302,9 +288,8 @@ public actual inline fun minOf(a: Float, b: Float): Float {
|
||||
*/
|
||||
@SinceKotlin("1.1")
|
||||
@kotlin.internal.InlineOnly
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
public actual inline fun minOf(a: Double, b: Double): Double {
|
||||
return Math.min(a, b)
|
||||
return JsMath.min(a, b)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -322,9 +307,8 @@ public actual fun <T : Comparable<T>> minOf(a: T, b: T, c: T): T {
|
||||
*/
|
||||
@SinceKotlin("1.1")
|
||||
@kotlin.internal.InlineOnly
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
public actual inline fun minOf(a: Byte, b: Byte, c: Byte): Byte {
|
||||
return Math.min(a.toInt(), b.toInt(), c.toInt()).unsafeCast<Byte>()
|
||||
return JsMath.min(a.toInt(), b.toInt(), c.toInt()).unsafeCast<Byte>()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -332,9 +316,8 @@ public actual inline fun minOf(a: Byte, b: Byte, c: Byte): Byte {
|
||||
*/
|
||||
@SinceKotlin("1.1")
|
||||
@kotlin.internal.InlineOnly
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
public actual inline fun minOf(a: Short, b: Short, c: Short): Short {
|
||||
return Math.min(a.toInt(), b.toInt(), c.toInt()).unsafeCast<Short>()
|
||||
return JsMath.min(a.toInt(), b.toInt(), c.toInt()).unsafeCast<Short>()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -342,9 +325,8 @@ public actual inline fun minOf(a: Short, b: Short, c: Short): Short {
|
||||
*/
|
||||
@SinceKotlin("1.1")
|
||||
@kotlin.internal.InlineOnly
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
public actual inline fun minOf(a: Int, b: Int, c: Int): Int {
|
||||
return Math.min(a, b, c)
|
||||
return JsMath.min(a, b, c)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -363,9 +345,8 @@ public actual inline fun minOf(a: Long, b: Long, c: Long): Long {
|
||||
*/
|
||||
@SinceKotlin("1.1")
|
||||
@kotlin.internal.InlineOnly
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
public actual inline fun minOf(a: Float, b: Float, c: Float): Float {
|
||||
return Math.min(a, b, c)
|
||||
return JsMath.min(a, b, c)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -375,9 +356,8 @@ public actual inline fun minOf(a: Float, b: Float, c: Float): Float {
|
||||
*/
|
||||
@SinceKotlin("1.1")
|
||||
@kotlin.internal.InlineOnly
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
public actual inline fun minOf(a: Double, b: Double, c: Double): Double {
|
||||
return Math.min(a, b, c)
|
||||
return JsMath.min(a, b, c)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2021 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.
|
||||
*/
|
||||
|
||||
@@ -8,100 +8,49 @@ package kotlin.js
|
||||
/**
|
||||
* Exposes the JavaScript [Math object](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Math) to Kotlin.
|
||||
*/
|
||||
@Deprecated("Use top-level functions from kotlin.math package instead.", level = DeprecationLevel.ERROR)
|
||||
public external object Math {
|
||||
@Deprecated("Use kotlin.math.PI instead.", ReplaceWith("PI", "kotlin.math.PI"), level = DeprecationLevel.ERROR)
|
||||
public val PI: Double
|
||||
@Deprecated("Use Random.nextDouble instead", ReplaceWith("kotlin.random.Random.nextDouble()", "kotlin.random.Random"), level = DeprecationLevel.ERROR)
|
||||
public fun random(): Double
|
||||
@Deprecated("Use kotlin.math.abs instead.", ReplaceWith("abs(value)", "kotlin.math.abs"), level = DeprecationLevel.ERROR)
|
||||
public fun abs(value: Double): Double
|
||||
@Deprecated("Use kotlin.math.acos instead.", ReplaceWith("acos(value)", "kotlin.math.acos"), level = DeprecationLevel.ERROR)
|
||||
public fun acos(value: Double): Double
|
||||
@Deprecated("Use kotlin.math.asin instead.", ReplaceWith("asin(value)", "kotlin.math.asin"), level = DeprecationLevel.ERROR)
|
||||
public fun asin(value: Double): Double
|
||||
@Deprecated("Use kotlin.math.atan instead.", ReplaceWith("atan(value)", "kotlin.math.atan"), level = DeprecationLevel.ERROR)
|
||||
public fun atan(value: Double): Double
|
||||
@Deprecated("Use kotlin.math.atan2 instead.", ReplaceWith("atan2(y, x)", "kotlin.math.atan2"), level = DeprecationLevel.ERROR)
|
||||
public fun atan2(y: Double, x: Double): Double
|
||||
@Deprecated("Use kotlin.math.cos instead.", ReplaceWith("cos(value)", "kotlin.math.cos"), level = DeprecationLevel.ERROR)
|
||||
public fun cos(value: Double): Double
|
||||
@Deprecated("Use kotlin.math.sin instead.", ReplaceWith("sin(value)", "kotlin.math.sin"), level = DeprecationLevel.ERROR)
|
||||
public fun sin(value: Double): Double
|
||||
@Deprecated("Use kotlin.math.exp instead.", ReplaceWith("exp(value)", "kotlin.math.exp"), level = DeprecationLevel.ERROR)
|
||||
public fun exp(value: Double): Double
|
||||
@Deprecated("Use maxOf or kotlin.math.max instead", level = DeprecationLevel.ERROR)
|
||||
public fun max(vararg values: Int): Int
|
||||
@Deprecated("Use maxOf or kotlin.math.max instead", level = DeprecationLevel.ERROR)
|
||||
public fun max(vararg values: Float): Float
|
||||
@Deprecated("Use maxOf or kotlin.math.max instead", level = DeprecationLevel.ERROR)
|
||||
public fun max(vararg values: Double): Double
|
||||
@Deprecated("Use minOf or kotlin.math.min instead", level = DeprecationLevel.ERROR)
|
||||
public fun min(vararg values: Int): Int
|
||||
@Deprecated("Use minOf or kotlin.math.min instead", level = DeprecationLevel.ERROR)
|
||||
public fun min(vararg values: Float): Float
|
||||
@Deprecated("Use minOf or kotlin.math.min instead", level = DeprecationLevel.ERROR)
|
||||
public fun min(vararg values: Double): Double
|
||||
@Deprecated("Use kotlin.math.sqrt instead.", ReplaceWith("sqrt(value)", "kotlin.math.sqrt"), level = DeprecationLevel.ERROR)
|
||||
public fun sqrt(value: Double): Double
|
||||
@Deprecated("Use kotlin.math.tan instead.", ReplaceWith("tan(value)", "kotlin.math.tan"), level = DeprecationLevel.ERROR)
|
||||
public fun tan(value: Double): Double
|
||||
@Deprecated("Use kotlin.math.ln instead.", ReplaceWith("ln(value)", "kotlin.math.ln"), level = DeprecationLevel.ERROR)
|
||||
public fun log(value: Double): Double
|
||||
@Deprecated("Use kotlin.math.pow instead.", ReplaceWith("base.pow(exp)", "kotlin.math.pow"), level = DeprecationLevel.ERROR)
|
||||
public fun pow(base: Double, exp: Double): Double
|
||||
@Deprecated("Use kotlin.math.round instead.", ReplaceWith("round(value)", "kotlin.math.round"), level = DeprecationLevel.ERROR)
|
||||
public fun round(value: Number): Int
|
||||
@Deprecated("Use kotlin.math.floor instead.", ReplaceWith("floor(value)", "kotlin.math.floor"), level = DeprecationLevel.ERROR)
|
||||
public fun floor(value: Number): Int
|
||||
@Deprecated("Use kotlin.math.ceil instead.", ReplaceWith("ceil(value)", "kotlin.math.ceil"), level = DeprecationLevel.ERROR)
|
||||
public fun ceil(value: Number): Int
|
||||
@PublishedApi
|
||||
@JsName("Math")
|
||||
internal external object JsMath {
|
||||
val LN2: Double
|
||||
fun abs(value: Double): Double
|
||||
fun acos(value: Double): Double
|
||||
fun asin(value: Double): Double
|
||||
fun atan(value: Double): Double
|
||||
fun atan2(y: Double, x: Double): Double
|
||||
fun cos(value: Double): Double
|
||||
fun sin(value: Double): Double
|
||||
fun exp(value: Double): Double
|
||||
fun max(vararg values: Int): Int
|
||||
fun max(vararg values: Float): Float
|
||||
fun max(vararg values: Double): Double
|
||||
fun min(vararg values: Int): Int
|
||||
fun min(vararg values: Float): Float
|
||||
fun min(vararg values: Double): Double
|
||||
fun sqrt(value: Double): Double
|
||||
fun tan(value: Double): Double
|
||||
fun log(value: Double): Double
|
||||
fun pow(base: Double, exp: Double): Double
|
||||
fun round(value: Number): Double
|
||||
fun floor(value: Number): Double
|
||||
fun ceil(value: Number): Double
|
||||
|
||||
@PublishedApi
|
||||
internal fun trunc(value: Number): Double
|
||||
@PublishedApi
|
||||
internal fun sign(value: Number): Double
|
||||
fun trunc(value: Number): Double
|
||||
fun sign(value: Number): Double
|
||||
|
||||
@PublishedApi
|
||||
internal fun sinh(value: Double): Double
|
||||
@PublishedApi
|
||||
internal fun cosh(value: Double): Double
|
||||
@PublishedApi
|
||||
internal fun tanh(value: Double): Double
|
||||
@PublishedApi
|
||||
internal fun asinh(value: Double): Double
|
||||
@PublishedApi
|
||||
internal fun acosh(value: Double): Double
|
||||
@PublishedApi
|
||||
internal fun atanh(value: Double): Double
|
||||
fun sinh(value: Double): Double
|
||||
fun cosh(value: Double): Double
|
||||
fun tanh(value: Double): Double
|
||||
fun asinh(value: Double): Double
|
||||
fun acosh(value: Double): Double
|
||||
fun atanh(value: Double): Double
|
||||
|
||||
@PublishedApi
|
||||
internal fun hypot(x: Double, y: Double): Double
|
||||
fun hypot(x: Double, y: Double): Double
|
||||
|
||||
@PublishedApi
|
||||
internal fun expm1(value: Double): Double
|
||||
fun expm1(value: Double): Double
|
||||
fun log10(value: Double): Double
|
||||
fun log2(value: Double): Double
|
||||
fun log1p(value: Double): Double
|
||||
|
||||
@PublishedApi
|
||||
internal fun log10(value: Double): Double
|
||||
@PublishedApi
|
||||
internal fun log2(value: Double): Double
|
||||
@PublishedApi
|
||||
internal fun log1p(value: Double): Double
|
||||
|
||||
@PublishedApi
|
||||
internal fun clz32(value: Int): Int
|
||||
fun clz32(value: Int): Int
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the smaller of two values.
|
||||
*/
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
@Deprecated("Use minOf or kotlin.math.min instead", ReplaceWith("minOf(a, b)"), level = DeprecationLevel.ERROR)
|
||||
public fun Math.min(a: Long, b: Long): Long = if (a <= b) a else b
|
||||
|
||||
/**
|
||||
* Returns the greater of two values.
|
||||
*/
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
@Deprecated("Use maxOf or kotlin.math.max instead", ReplaceWith("maxOf(a, b)"), level = DeprecationLevel.ERROR)
|
||||
public fun Math.max(a: Long, b: Long): Long = if (a >= b) a else b
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2021 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.
|
||||
*/
|
||||
@file:Suppress("DEPRECATION_ERROR")
|
||||
package kotlin.math
|
||||
|
||||
|
||||
import kotlin.internal.InlineOnly
|
||||
import kotlin.js.Math as nativeMath
|
||||
import kotlin.js.JsMath as nativeMath
|
||||
|
||||
|
||||
// region ================ Double Math ========================================
|
||||
@@ -296,7 +295,7 @@ public actual inline fun ln1p(x: Double): Double = nativeMath.log1p(x)
|
||||
*/
|
||||
@SinceKotlin("1.2")
|
||||
@InlineOnly
|
||||
public actual inline fun ceil(x: Double): Double = nativeMath.ceil(x).unsafeCast<Double>() // TODO: Remove unsafe cast after removing public js.math
|
||||
public actual inline fun ceil(x: Double): Double = nativeMath.ceil(x)
|
||||
|
||||
/**
|
||||
* Rounds the given value [x] to an integer towards negative infinity.
|
||||
@@ -308,7 +307,7 @@ public actual inline fun ceil(x: Double): Double = nativeMath.ceil(x).unsafeCast
|
||||
*/
|
||||
@SinceKotlin("1.2")
|
||||
@InlineOnly
|
||||
public actual inline fun floor(x: Double): Double = nativeMath.floor(x).unsafeCast<Double>()
|
||||
public actual inline fun floor(x: Double): Double = nativeMath.floor(x)
|
||||
|
||||
/**
|
||||
* Rounds the given value [x] to an integer towards zero.
|
||||
@@ -331,7 +330,7 @@ public actual inline fun truncate(x: Double): Double = nativeMath.trunc(x)
|
||||
@SinceKotlin("1.2")
|
||||
public actual fun round(x: Double): Double {
|
||||
if (x % 0.5 != 0.0) {
|
||||
return nativeMath.round(x).unsafeCast<Double>()
|
||||
return nativeMath.round(x)
|
||||
}
|
||||
val floor = floor(x)
|
||||
return if (floor % 2 == 0.0) floor else ceil(x)
|
||||
@@ -510,7 +509,7 @@ public actual fun Double.roundToInt(): Int = when {
|
||||
isNaN() -> throw IllegalArgumentException("Cannot round NaN value.")
|
||||
this > Int.MAX_VALUE -> Int.MAX_VALUE
|
||||
this < Int.MIN_VALUE -> Int.MIN_VALUE
|
||||
else -> nativeMath.round(this).unsafeCast<Double>().toInt()
|
||||
else -> nativeMath.round(this).toInt()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -528,7 +527,7 @@ public actual fun Double.roundToLong(): Long = when {
|
||||
isNaN() -> throw IllegalArgumentException("Cannot round NaN value.")
|
||||
this > Long.MAX_VALUE -> Long.MAX_VALUE
|
||||
this < Long.MIN_VALUE -> Long.MIN_VALUE
|
||||
else -> nativeMath.round(this).unsafeCast<Double>().toLong()
|
||||
else -> nativeMath.round(this).toLong()
|
||||
}
|
||||
|
||||
// endregion
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2021 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.
|
||||
*/
|
||||
|
||||
@@ -59,9 +59,8 @@ public actual fun Int.countOneBits(): Int {
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
@WasExperimental(ExperimentalStdlibApi::class)
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
@kotlin.internal.InlineOnly
|
||||
public actual inline fun Int.countLeadingZeroBits(): Int = kotlin.js.Math.clz32(this)
|
||||
public actual inline fun Int.countLeadingZeroBits(): Int = JsMath.clz32(this)
|
||||
|
||||
/**
|
||||
* Counts the number of consecutive least significant bits that are zero in the binary representation of this [Int] number.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2021 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.
|
||||
*/
|
||||
|
||||
@@ -13,8 +13,7 @@ internal actual fun formatToExactDecimals(value: Double, decimals: Int): String
|
||||
value
|
||||
} else {
|
||||
val pow = 10.0.pow(decimals)
|
||||
@Suppress("DEPRECATION", "DEPRECATION_ERROR")
|
||||
kotlin.js.Math.round(abs(value) * pow) / pow * sign(value)
|
||||
JsMath.round(abs(value) * pow) / pow * sign(value)
|
||||
}
|
||||
return rounded.asDynamic().toFixed(decimals).unsafeCast<String>()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user