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:
Ilya Gorbunov
2021-04-06 07:20:02 +03:00
parent d9ab96126d
commit d70edeb38b
10 changed files with 109 additions and 375 deletions
-78
View File
@@ -43,12 +43,6 @@ public inline operator fun kotlin.js.RegExpMatch.get(index: kotlin.Int): kotlin.
@kotlin.internal.DynamicExtension
public operator fun dynamic.iterator(): kotlin.collections.Iterator<dynamic>
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use maxOf or kotlin.math.max instead", replaceWith = kotlin.ReplaceWith(expression = "maxOf(a, b)", imports = {}))
public fun kotlin.js.Math.max(a: kotlin.Long, b: kotlin.Long): kotlin.Long
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use minOf or kotlin.math.min instead", replaceWith = kotlin.ReplaceWith(expression = "minOf(a, b)", imports = {}))
public fun kotlin.js.Math.min(a: kotlin.Long, b: kotlin.Long): kotlin.Long
public fun kotlin.js.RegExp.reset(): kotlin.Unit
public inline fun <T, S> kotlin.js.Promise<kotlin.js.Promise<T>>.then(noinline onFulfilled: ((T) -> S)?): kotlin.js.Promise<S>
@@ -276,78 +270,6 @@ public external interface Json {
public abstract operator fun set(propertyName: kotlin.String, value: kotlin.Any?): kotlin.Unit
}
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use top-level functions from kotlin.math package instead.")
public external object Math {
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use kotlin.math.PI instead.", replaceWith = kotlin.ReplaceWith(expression = "PI", imports = {"kotlin.math.PI"}))
public final val PI: kotlin.Double { get; }
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use kotlin.math.abs instead.", replaceWith = kotlin.ReplaceWith(expression = "abs(value)", imports = {"kotlin.math.abs"}))
public final fun abs(value: kotlin.Double): kotlin.Double
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use kotlin.math.acos instead.", replaceWith = kotlin.ReplaceWith(expression = "acos(value)", imports = {"kotlin.math.acos"}))
public final fun acos(value: kotlin.Double): kotlin.Double
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use kotlin.math.asin instead.", replaceWith = kotlin.ReplaceWith(expression = "asin(value)", imports = {"kotlin.math.asin"}))
public final fun asin(value: kotlin.Double): kotlin.Double
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use kotlin.math.atan instead.", replaceWith = kotlin.ReplaceWith(expression = "atan(value)", imports = {"kotlin.math.atan"}))
public final fun atan(value: kotlin.Double): kotlin.Double
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use kotlin.math.atan2 instead.", replaceWith = kotlin.ReplaceWith(expression = "atan2(y, x)", imports = {"kotlin.math.atan2"}))
public final fun atan2(y: kotlin.Double, x: kotlin.Double): kotlin.Double
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use kotlin.math.ceil instead.", replaceWith = kotlin.ReplaceWith(expression = "ceil(value)", imports = {"kotlin.math.ceil"}))
public final fun ceil(value: kotlin.Number): kotlin.Int
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use kotlin.math.cos instead.", replaceWith = kotlin.ReplaceWith(expression = "cos(value)", imports = {"kotlin.math.cos"}))
public final fun cos(value: kotlin.Double): kotlin.Double
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use kotlin.math.exp instead.", replaceWith = kotlin.ReplaceWith(expression = "exp(value)", imports = {"kotlin.math.exp"}))
public final fun exp(value: kotlin.Double): kotlin.Double
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use kotlin.math.floor instead.", replaceWith = kotlin.ReplaceWith(expression = "floor(value)", imports = {"kotlin.math.floor"}))
public final fun floor(value: kotlin.Number): kotlin.Int
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use kotlin.math.ln instead.", replaceWith = kotlin.ReplaceWith(expression = "ln(value)", imports = {"kotlin.math.ln"}))
public final fun log(value: kotlin.Double): kotlin.Double
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use maxOf or kotlin.math.max instead")
public final fun max(vararg values: kotlin.Double): kotlin.Double
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use maxOf or kotlin.math.max instead")
public final fun max(vararg values: kotlin.Float): kotlin.Float
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use maxOf or kotlin.math.max instead")
public final fun max(vararg values: kotlin.Int): kotlin.Int
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use minOf or kotlin.math.min instead")
public final fun min(vararg values: kotlin.Double): kotlin.Double
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use minOf or kotlin.math.min instead")
public final fun min(vararg values: kotlin.Float): kotlin.Float
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use minOf or kotlin.math.min instead")
public final fun min(vararg values: kotlin.Int): kotlin.Int
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use kotlin.math.pow instead.", replaceWith = kotlin.ReplaceWith(expression = "base.pow(exp)", imports = {"kotlin.math.pow"}))
public final fun pow(base: kotlin.Double, exp: kotlin.Double): kotlin.Double
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use Random.nextDouble instead", replaceWith = kotlin.ReplaceWith(expression = "kotlin.random.Random.nextDouble()", imports = {"kotlin.random.Random"}))
public final fun random(): kotlin.Double
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use kotlin.math.round instead.", replaceWith = kotlin.ReplaceWith(expression = "round(value)", imports = {"kotlin.math.round"}))
public final fun round(value: kotlin.Number): kotlin.Int
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use kotlin.math.sin instead.", replaceWith = kotlin.ReplaceWith(expression = "sin(value)", imports = {"kotlin.math.sin"}))
public final fun sin(value: kotlin.Double): kotlin.Double
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use kotlin.math.sqrt instead.", replaceWith = kotlin.ReplaceWith(expression = "sqrt(value)", imports = {"kotlin.math.sqrt"}))
public final fun sqrt(value: kotlin.Double): kotlin.Double
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use kotlin.math.tan instead.", replaceWith = kotlin.ReplaceWith(expression = "tan(value)", imports = {"kotlin.math.tan"}))
public final fun tan(value: kotlin.Double): kotlin.Double
}
public open external class Promise<out T> {
public constructor Promise<out T>(executor: (resolve: (T) -> kotlin.Unit, reject: (kotlin.Throwable) -> kotlin.Unit) -> kotlin.Unit)
-78
View File
@@ -42,12 +42,6 @@ public inline operator fun kotlin.js.RegExpMatch.get(index: kotlin.Int): kotlin.
@kotlin.internal.DynamicExtension
public operator fun dynamic.iterator(): kotlin.collections.Iterator<dynamic>
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use maxOf or kotlin.math.max instead", replaceWith = kotlin.ReplaceWith(expression = "maxOf(a, b)", imports = {}))
public fun kotlin.js.Math.max(a: kotlin.Long, b: kotlin.Long): kotlin.Long
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use minOf or kotlin.math.min instead", replaceWith = kotlin.ReplaceWith(expression = "minOf(a, b)", imports = {}))
public fun kotlin.js.Math.min(a: kotlin.Long, b: kotlin.Long): kotlin.Long
public fun kotlin.js.RegExp.reset(): kotlin.Unit
public inline fun <T, S> kotlin.js.Promise<kotlin.js.Promise<T>>.then(noinline onFulfilled: ((T) -> S)?): kotlin.js.Promise<S>
@@ -275,78 +269,6 @@ public external interface Json {
public abstract operator fun set(propertyName: kotlin.String, value: kotlin.Any?): kotlin.Unit
}
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use top-level functions from kotlin.math package instead.")
public external object Math {
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use kotlin.math.PI instead.", replaceWith = kotlin.ReplaceWith(expression = "PI", imports = {"kotlin.math.PI"}))
public final val PI: kotlin.Double { get; }
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use kotlin.math.abs instead.", replaceWith = kotlin.ReplaceWith(expression = "abs(value)", imports = {"kotlin.math.abs"}))
public final fun abs(value: kotlin.Double): kotlin.Double
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use kotlin.math.acos instead.", replaceWith = kotlin.ReplaceWith(expression = "acos(value)", imports = {"kotlin.math.acos"}))
public final fun acos(value: kotlin.Double): kotlin.Double
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use kotlin.math.asin instead.", replaceWith = kotlin.ReplaceWith(expression = "asin(value)", imports = {"kotlin.math.asin"}))
public final fun asin(value: kotlin.Double): kotlin.Double
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use kotlin.math.atan instead.", replaceWith = kotlin.ReplaceWith(expression = "atan(value)", imports = {"kotlin.math.atan"}))
public final fun atan(value: kotlin.Double): kotlin.Double
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use kotlin.math.atan2 instead.", replaceWith = kotlin.ReplaceWith(expression = "atan2(y, x)", imports = {"kotlin.math.atan2"}))
public final fun atan2(y: kotlin.Double, x: kotlin.Double): kotlin.Double
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use kotlin.math.ceil instead.", replaceWith = kotlin.ReplaceWith(expression = "ceil(value)", imports = {"kotlin.math.ceil"}))
public final fun ceil(value: kotlin.Number): kotlin.Int
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use kotlin.math.cos instead.", replaceWith = kotlin.ReplaceWith(expression = "cos(value)", imports = {"kotlin.math.cos"}))
public final fun cos(value: kotlin.Double): kotlin.Double
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use kotlin.math.exp instead.", replaceWith = kotlin.ReplaceWith(expression = "exp(value)", imports = {"kotlin.math.exp"}))
public final fun exp(value: kotlin.Double): kotlin.Double
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use kotlin.math.floor instead.", replaceWith = kotlin.ReplaceWith(expression = "floor(value)", imports = {"kotlin.math.floor"}))
public final fun floor(value: kotlin.Number): kotlin.Int
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use kotlin.math.ln instead.", replaceWith = kotlin.ReplaceWith(expression = "ln(value)", imports = {"kotlin.math.ln"}))
public final fun log(value: kotlin.Double): kotlin.Double
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use maxOf or kotlin.math.max instead")
public final fun max(vararg values: kotlin.Double): kotlin.Double
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use maxOf or kotlin.math.max instead")
public final fun max(vararg values: kotlin.Float): kotlin.Float
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use maxOf or kotlin.math.max instead")
public final fun max(vararg values: kotlin.Int): kotlin.Int
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use minOf or kotlin.math.min instead")
public final fun min(vararg values: kotlin.Double): kotlin.Double
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use minOf or kotlin.math.min instead")
public final fun min(vararg values: kotlin.Float): kotlin.Float
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use minOf or kotlin.math.min instead")
public final fun min(vararg values: kotlin.Int): kotlin.Int
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use kotlin.math.pow instead.", replaceWith = kotlin.ReplaceWith(expression = "base.pow(exp)", imports = {"kotlin.math.pow"}))
public final fun pow(base: kotlin.Double, exp: kotlin.Double): kotlin.Double
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use Random.nextDouble instead", replaceWith = kotlin.ReplaceWith(expression = "kotlin.random.Random.nextDouble()", imports = {"kotlin.random.Random"}))
public final fun random(): kotlin.Double
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use kotlin.math.round instead.", replaceWith = kotlin.ReplaceWith(expression = "round(value)", imports = {"kotlin.math.round"}))
public final fun round(value: kotlin.Number): kotlin.Int
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use kotlin.math.sin instead.", replaceWith = kotlin.ReplaceWith(expression = "sin(value)", imports = {"kotlin.math.sin"}))
public final fun sin(value: kotlin.Double): kotlin.Double
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use kotlin.math.sqrt instead.", replaceWith = kotlin.ReplaceWith(expression = "sqrt(value)", imports = {"kotlin.math.sqrt"}))
public final fun sqrt(value: kotlin.Double): kotlin.Double
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use kotlin.math.tan instead.", replaceWith = kotlin.ReplaceWith(expression = "tan(value)", imports = {"kotlin.math.tan"}))
public final fun tan(value: kotlin.Double): kotlin.Double
}
public open external class Promise<out T> {
public constructor Promise<out T>(executor: (resolve: (T) -> kotlin.Unit, reject: (kotlin.Throwable) -> kotlin.Unit) -> kotlin.Unit)
+2 -12
View File
@@ -1,9 +1,8 @@
/*
* Copyright 2010-2018 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.
*/
// Copyright 2009 The Closure Library Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -259,7 +258,7 @@ internal fun Long.divide(other: Long): Long {
// We will tweak the approximate result by changing it in the 48-th digit or
// the smallest non-fractional digit, whichever is larger.
val log2 = JsMath.ceil(JsMath.log(approx2) / JsMath.LN2)
val delta = if (log2 <= 48) 1.0 else JsMath.pow(2, log2 - 48)
val delta = if (log2 <= 48) 1.0 else JsMath.pow(2.0, log2 - 48)
// Decrease the approximation until it is smaller than the remainder. Note
// that if it is too large, the product overflows and is negative.
@@ -386,13 +385,4 @@ private val MIN_VALUE = Long(0, 1 shl 31)
private val TWO_PWR_24_ = fromInt(1 shl 24)
@JsName("Math")
internal external object JsMath {
fun max(lhs: Number, rhs: Number): Double
fun floor(x: Number): Double
fun ceil(x: Number): Double
fun log(x: Number): Double
fun pow(base: Number, exponent: Number): Double
val LN2: Double
}
@@ -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)
}
/**
@@ -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)
}
/**
+40 -91
View File
@@ -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
+7 -8
View File
@@ -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
+2 -3
View File
@@ -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>()
}
@@ -182,23 +182,22 @@ object ComparableOps : TemplateGroupBase() {
inlineOnly()
var convertBack = "to$primitive()"
on(Platform.JS) {
suppress("DEPRECATION_ERROR")
convertBack = "unsafeCast<$primitive>()"
}
on(Platform.JVM) {
body { "return Math.min(a, b)" }
}
on(Platform.JS) {
body { "return Math.min(a, b)" }
body { "return JsMath.min(a, b)" }
if (primitive == PrimitiveType.Long) {
inline(suppressWarning = true)
body { "return $defaultImpl" }
}
}
if (primitive in shortIntPrimitives) {
body { "return Math.min(a.toInt(), b.toInt()).$convertBack" }
on(Platform.Native) {
body { "return minOf(a.toInt(), b.toInt()).$convertBack" }
body { "return minOf(a.toInt(), b.toInt()).$convertBack" }
on(Platform.JVM) {
body { "return Math.min(a.toInt(), b.toInt()).$convertBack" }
}
}
if (isFloat) {
@@ -254,14 +253,12 @@ object ComparableOps : TemplateGroupBase() {
body { "return Math.min(a.toInt(), Math.min(b.toInt(), c.toInt())).to$primitive()" }
}
on(Platform.JS) {
suppress("DEPRECATION_ERROR")
body { "return Math.min(a.toInt(), b.toInt(), c.toInt()).unsafeCast<$primitive>()" }
body { "return JsMath.min(a.toInt(), b.toInt(), c.toInt()).unsafeCast<$primitive>()" }
}
}
else if (primitive != PrimitiveType.Long) {
on(Platform.JS) {
suppress("DEPRECATION_ERROR")
body { "return Math.min(a, b, c)" }
body { "return JsMath.min(a, b, c)" }
}
}
}
@@ -386,23 +383,22 @@ object ComparableOps : TemplateGroupBase() {
inlineOnly()
var convertBack = "to$primitive()"
on(Platform.JS) {
suppress("DEPRECATION_ERROR")
convertBack = "unsafeCast<$primitive>()"
}
on(Platform.JVM) {
body { "return Math.max(a, b)" }
}
on(Platform.JS) {
body { "return Math.max(a, b)" }
body { "return JsMath.max(a, b)" }
if (primitive == PrimitiveType.Long) {
inline(suppressWarning = true)
body { "return $defaultImpl" }
}
}
if (primitive in shortIntPrimitives) {
body { "return Math.max(a.toInt(), b.toInt()).$convertBack" }
on(Platform.Native) {
body { "return maxOf(a.toInt(), b.toInt()).$convertBack" }
body { "return maxOf(a.toInt(), b.toInt()).$convertBack" }
on(Platform.JVM) {
body { "return Math.max(a.toInt(), b.toInt()).$convertBack" }
}
}
if (isFloat) {
@@ -454,14 +450,12 @@ object ComparableOps : TemplateGroupBase() {
body { "return Math.max(a.toInt(), Math.max(b.toInt(), c.toInt())).to$primitive()" }
}
on(Platform.JS) {
suppress("DEPRECATION_ERROR")
body { "return Math.max(a.toInt(), b.toInt(), c.toInt()).unsafeCast<$primitive>()" }
body { "return JsMath.max(a.toInt(), b.toInt(), c.toInt()).unsafeCast<$primitive>()" }
}
}
else if (primitive != PrimitiveType.Long) {
on(Platform.JS) {
suppress("DEPRECATION_ERROR")
body { "return Math.max(a, b, c)" }
body { "return JsMath.max(a, b, c)" }
}
}
}