Rename log to ln, log1p to ln1p, keep pow only as extension
#KT-4900
This commit is contained in:
@@ -150,28 +150,6 @@ public inline fun tanh(a: Double): Double = nativeMath.tanh(a)
|
||||
@InlineOnly
|
||||
public inline fun hypot(x: Double, y: Double): Double = nativeMath.hypot(x, y)
|
||||
|
||||
/**
|
||||
* Raises the first argument [a] to the power of the second argument [b].
|
||||
*
|
||||
* Special cases:
|
||||
* - `pow(x, 0.0)` is `1.0`
|
||||
* - `pow(x, 1.0) == x`
|
||||
* - `pow(x, NaN)` is `NaN`
|
||||
* - `pow(NaN, x)` is `NaN` for `x != 0.0`
|
||||
* - `pow(x, Inf)` is `NaN` for `abs(x) == 1.0`
|
||||
* - `pow(x, y)` is `NaN` for `x < 0` and `y` is finite and not an integer
|
||||
*/
|
||||
@InlineOnly
|
||||
public inline fun pow(a: Double, b: Double): Double = nativeMath.pow(a, b)
|
||||
|
||||
/**
|
||||
* Raises the first argument [a] to the integer power of the second argument [b].
|
||||
*
|
||||
* See the other overload of [pow] for details.
|
||||
*/
|
||||
@InlineOnly
|
||||
public inline fun pow(a: Double, b: Int): Double = nativeMath.pow(a, b.toDouble())
|
||||
|
||||
/**
|
||||
* Computes the positive square root of the value [a].
|
||||
*
|
||||
@@ -226,18 +204,18 @@ public fun log(a: Double, base: Double): Double {
|
||||
* Computes the natural logarithm (base `E`) of the [a] value.
|
||||
*
|
||||
* Special cases:
|
||||
* - `log(NaN)` is `NaN`
|
||||
* - `log(x)` is `NaN` when `x < 0.0`
|
||||
* - `log(+Inf)` is `+Inf`
|
||||
* - `log(0.0)` is `-Inf`
|
||||
* - `ln(NaN)` is `NaN`
|
||||
* - `ln(x)` is `NaN` when `x < 0.0`
|
||||
* - `ln(+Inf)` is `+Inf`
|
||||
* - `ln(0.0)` is `-Inf`
|
||||
*/
|
||||
@InlineOnly
|
||||
public inline fun log(a: Double): Double = nativeMath.log(a)
|
||||
public inline fun ln(a: Double): Double = nativeMath.log(a)
|
||||
|
||||
/**
|
||||
* Computes the decimal logarithm (base 10) of the [a] value.
|
||||
*
|
||||
* @see [log] function for special cases.
|
||||
* @see [ln] function for special cases.
|
||||
*/
|
||||
@InlineOnly
|
||||
public inline fun log10(a: Double): Double = nativeMath.log10(a)
|
||||
@@ -245,7 +223,7 @@ public inline fun log10(a: Double): Double = nativeMath.log10(a)
|
||||
/**
|
||||
* Computes the binary logarithm (base 2) of the [a] value.
|
||||
*
|
||||
* @see [log] function for special cases.
|
||||
* @see [ln] function for special cases.
|
||||
*/
|
||||
@InlineOnly
|
||||
public inline fun log2(a: Double): Double = nativeMath.log2(a)
|
||||
@@ -261,10 +239,11 @@ public inline fun log2(a: Double): Double = nativeMath.log2(a)
|
||||
* - `log1p(-1.0)` is `-Inf`
|
||||
* - `log1p(+Inf)` is `+Inf`
|
||||
*
|
||||
* @see [log] function.
|
||||
* @see [ln] function.
|
||||
* @see [expm1] function
|
||||
*/
|
||||
@InlineOnly
|
||||
public inline fun log1p(a: Double): Double = nativeMath.log1p(a)
|
||||
public inline fun ln1p(a: Double): Double = nativeMath.log1p(a)
|
||||
|
||||
/**
|
||||
* Rounds the given value [a] to an integer towards positive infinity.
|
||||
@@ -354,8 +333,27 @@ public inline fun max(a: Double, b: Double): Double = nativeMath.max(a, b)
|
||||
|
||||
// extensions
|
||||
|
||||
inline fun Double.pow(other: Double): Double = nativeMath.pow(this, other)
|
||||
inline fun Double.pow(other: Int): Double = nativeMath.pow(this, other.toDouble())
|
||||
/**
|
||||
* Raises this value to the power [other].
|
||||
*
|
||||
* Special cases:
|
||||
* - `x.pow(0.0)` is `1.0`
|
||||
* - `x.pow(1.0) == x`
|
||||
* - `x.pow(NaN)` is `NaN`
|
||||
* - `NaN.pow(x)` is `NaN` for `x != 0.0`
|
||||
* - `x.pow(Inf)` is `NaN` for `abs(x) == 1.0`
|
||||
* - `x.pow(y)` is `NaN` for `x < 0` and `y` is finite and not an integer
|
||||
*/
|
||||
@InlineOnly
|
||||
public inline fun Double.pow(other: Double): Double = nativeMath.pow(this, other)
|
||||
|
||||
/**
|
||||
* Raises this value to the integer power [other].
|
||||
*
|
||||
* See the other overload of [pow] for details.
|
||||
*/
|
||||
@InlineOnly
|
||||
public inline fun Double.pow(other: Int): Double = nativeMath.pow(this, other.toDouble())
|
||||
|
||||
/**
|
||||
* Returns the absolute value of this value.
|
||||
|
||||
@@ -28,7 +28,7 @@ public const val PI: Double = nativeMath.PI
|
||||
/** Base of the natural logarithms, approximately 2.71828. */
|
||||
public const val E: Double = nativeMath.E
|
||||
/** Natural logarithm of 2.0, used to compute [log2] function */
|
||||
private val LN2: Double = log(2.0)
|
||||
private val LN2: Double = ln(2.0)
|
||||
|
||||
// Double
|
||||
|
||||
@@ -153,28 +153,6 @@ public inline fun tanh(a: Double): Double = nativeMath.tanh(a)
|
||||
@InlineOnly
|
||||
public inline fun hypot(x: Double, y: Double): Double = nativeMath.hypot(x, y)
|
||||
|
||||
/**
|
||||
* Raises the first argument [a] to the power of the second argument [b].
|
||||
*
|
||||
* Special cases:
|
||||
* - `pow(x, 0.0)` is `1.0`
|
||||
* - `pow(x, 1.0) == x`
|
||||
* - `pow(x, NaN)` is `NaN`
|
||||
* - `pow(NaN, x)` is `NaN` for `x != 0.0`
|
||||
* - `pow(x, Inf)` is `NaN` for `abs(x) == 1.0`
|
||||
* - `pow(x, y)` is `NaN` for `x < 0` and `y` is finite and not an integer
|
||||
*/
|
||||
@InlineOnly
|
||||
public inline fun pow(a: Double, b: Double): Double = nativeMath.pow(a, b)
|
||||
|
||||
/**
|
||||
* Raises the first argument [a] to the integer power of the second argument [b].
|
||||
*
|
||||
* See the other overload of [pow] for details.
|
||||
*/
|
||||
@InlineOnly
|
||||
public inline fun pow(a: Double, b: Int): Double = nativeMath.pow(a, b.toDouble())
|
||||
|
||||
/**
|
||||
* Computes the positive square root of the value [a].
|
||||
*
|
||||
@@ -229,18 +207,18 @@ public fun log(a: Double, base: Double): Double {
|
||||
* Computes the natural logarithm (base `E`) of the [a] value.
|
||||
*
|
||||
* Special cases:
|
||||
* - `log(NaN)` is `NaN`
|
||||
* - `log(x)` is `NaN` when `x < 0.0`
|
||||
* - `log(+Inf)` is `+Inf`
|
||||
* - `log(0.0)` is `-Inf`
|
||||
* - `ln(NaN)` is `NaN`
|
||||
* - `ln(x)` is `NaN` when `x < 0.0`
|
||||
* - `ln(+Inf)` is `+Inf`
|
||||
* - `ln(0.0)` is `-Inf`
|
||||
*/
|
||||
@InlineOnly
|
||||
public inline fun log(a: Double): Double = nativeMath.log(a)
|
||||
public inline fun ln(a: Double): Double = nativeMath.log(a)
|
||||
|
||||
/**
|
||||
* Computes the decimal logarithm (base 10) of the [a] value.
|
||||
*
|
||||
* @see [log] function for special cases.
|
||||
* @see [ln] function for special cases.
|
||||
*/
|
||||
@InlineOnly
|
||||
public inline fun log10(a: Double): Double = nativeMath.log10(a)
|
||||
@@ -248,7 +226,7 @@ public inline fun log10(a: Double): Double = nativeMath.log10(a)
|
||||
/**
|
||||
* Computes the binary logarithm (base 2) of the [a] value.
|
||||
*
|
||||
* @see [log] function for special cases.
|
||||
* @see [ln] function for special cases.
|
||||
*/
|
||||
public fun log2(a: Double): Double = nativeMath.log(a) / LN2
|
||||
|
||||
@@ -263,10 +241,11 @@ public fun log2(a: Double): Double = nativeMath.log(a) / LN2
|
||||
* - `log1p(-1.0)` is `-Inf`
|
||||
* - `log1p(+Inf)` is `+Inf`
|
||||
*
|
||||
* @see [log] function.
|
||||
* @see [ln] function
|
||||
* @see [expm1] function
|
||||
*/
|
||||
@InlineOnly
|
||||
public inline fun log1p(a: Double): Double = nativeMath.log1p(a)
|
||||
public inline fun ln1p(a: Double): Double = nativeMath.log1p(a)
|
||||
|
||||
/**
|
||||
* Rounds the given value [a] to an integer towards positive infinity.
|
||||
@@ -356,22 +335,27 @@ public inline fun max(a: Double, b: Double): Double = nativeMath.max(a, b)
|
||||
|
||||
// extensions
|
||||
|
||||
|
||||
/**
|
||||
* Raises this value to the power [other].
|
||||
*
|
||||
* See the [pow] top-level function for details.
|
||||
* Special cases:
|
||||
* - `x.pow(0.0)` is `1.0`
|
||||
* - `x.pow(1.0) == x`
|
||||
* - `x.pow(NaN)` is `NaN`
|
||||
* - `NaN.pow(x)` is `NaN` for `x != 0.0`
|
||||
* - `x.pow(Inf)` is `NaN` for `abs(x) == 1.0`
|
||||
* - `x.pow(y)` is `NaN` for `x < 0` and `y` is finite and not an integer
|
||||
*/
|
||||
@InlineOnly
|
||||
@JvmName("power")
|
||||
public inline fun Double.pow(other: Double): Double = nativeMath.pow(this, other)
|
||||
|
||||
/**
|
||||
* Raises this value to the integer power [other].
|
||||
*
|
||||
* See the [pow] top-level function for details.
|
||||
* See the other overload of [pow] for details.
|
||||
*/
|
||||
@InlineOnly
|
||||
@JvmName("power")
|
||||
public inline fun Double.pow(other: Int): Double = nativeMath.pow(this, other.toDouble())
|
||||
|
||||
|
||||
|
||||
@@ -89,15 +89,15 @@ class DoubleMathTest {
|
||||
assertEquals(Double.POSITIVE_INFINITY, hypot(Double.NaN, Double.POSITIVE_INFINITY))
|
||||
assertTrue(hypot(Double.NaN, 0.0).isNaN())
|
||||
|
||||
assertEquals(1.0, pow(Double.NaN, 0.0))
|
||||
assertEquals(1.0, Double.NaN.pow(0.0))
|
||||
assertEquals(1.0, Double.POSITIVE_INFINITY.pow(0))
|
||||
assertEquals(49.0, pow(7.0, 2))
|
||||
assertEquals(0.25, pow(2.0, -2))
|
||||
assertTrue(pow(0.0, Double.NaN).isNaN())
|
||||
assertTrue(pow(Double.NaN, -1).isNaN())
|
||||
assertTrue(pow(-7.0, 1/3.0).isNaN())
|
||||
assertTrue(pow(1.0, Double.POSITIVE_INFINITY).isNaN())
|
||||
assertTrue(pow(-1.0, Double.NEGATIVE_INFINITY).isNaN())
|
||||
assertEquals(49.0, 7.0.pow(2))
|
||||
assertEquals(0.25, 2.0.pow(-2))
|
||||
assertTrue(0.0.pow(Double.NaN).isNaN())
|
||||
assertTrue(Double.NaN.pow(-1).isNaN())
|
||||
assertTrue((-7.0).pow(1/3.0).isNaN())
|
||||
assertTrue(1.0.pow(Double.POSITIVE_INFINITY).isNaN())
|
||||
assertTrue((-1.0).pow(Double.NEGATIVE_INFINITY).isNaN())
|
||||
|
||||
assertEquals(5.0, sqrt(9.0 + 16.0))
|
||||
assertTrue(sqrt(-1.0).isNaN())
|
||||
@@ -129,11 +129,11 @@ class DoubleMathTest {
|
||||
assertEquals(Double.NEGATIVE_INFINITY, log(0.0, 2.0))
|
||||
assertEquals(Double.POSITIVE_INFINITY, log(0.0, 0.25))
|
||||
|
||||
assertTrue(log(Double.NaN).isNaN())
|
||||
assertTrue(log(-1.0).isNaN())
|
||||
assertEquals(1.0, log(E))
|
||||
assertEquals(Double.NEGATIVE_INFINITY, log(0.0))
|
||||
assertEquals(Double.POSITIVE_INFINITY, log(Double.POSITIVE_INFINITY))
|
||||
assertTrue(ln(Double.NaN).isNaN())
|
||||
assertTrue(ln(-1.0).isNaN())
|
||||
assertEquals(1.0, ln(E))
|
||||
assertEquals(Double.NEGATIVE_INFINITY, ln(0.0))
|
||||
assertEquals(Double.POSITIVE_INFINITY, ln(Double.POSITIVE_INFINITY))
|
||||
|
||||
assertEquals(1.0, log10(10.0))
|
||||
assertAlmostEquals(-1.0, log10(0.1))
|
||||
@@ -141,10 +141,10 @@ class DoubleMathTest {
|
||||
assertAlmostEquals(3.0, log2(8.0))
|
||||
assertEquals(-1.0, log2(0.5))
|
||||
|
||||
assertTrue(log1p(Double.NaN).isNaN())
|
||||
assertTrue(log1p(-1.1).isNaN())
|
||||
assertEquals(0.0, log1p(0.0))
|
||||
assertEquals(Double.NEGATIVE_INFINITY, log1p(-1.0))
|
||||
assertTrue(ln1p(Double.NaN).isNaN())
|
||||
assertTrue(ln1p(-1.1).isNaN())
|
||||
assertEquals(0.0, ln1p(0.0))
|
||||
assertEquals(Double.NEGATIVE_INFINITY, ln1p(-1.0))
|
||||
}
|
||||
|
||||
@Test fun rounding() {
|
||||
|
||||
Reference in New Issue
Block a user