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:
@@ -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)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user