KT-48232: Implement kotlin.math.cbrt() (cubic roots)
cbrt() is the standard cubic root function that provides several advantages over pow(x, 1.0/3.0): - Better precision - Faster - Behaves better with negative values
This commit is contained in:
@@ -354,6 +354,22 @@ public expect fun min(a: Double, b: Double): Double
|
||||
@SinceKotlin("1.2")
|
||||
public expect fun max(a: Double, b: Double): Double
|
||||
|
||||
|
||||
/**
|
||||
* Returns the cube root of [x]. For any `x`, `cbrt(-x) == -cbrt(x)`;
|
||||
* that is, the cube root of a negative value is the negative of the cube root
|
||||
* of that value's magnitude. Special cases:
|
||||
*
|
||||
* Special cases:
|
||||
* - If the argument is `NaN`, then the result is `NaN`.
|
||||
* - If the argument is infinite, then the result is an infinity with the same sign as the argument.
|
||||
* - If the argument is zero, then the result is a zero with the same sign as the argument.
|
||||
*/
|
||||
@SinceKotlin("1.7")
|
||||
@ExperimentalStdlibApi
|
||||
public expect fun cbrt(x: Double): Double
|
||||
|
||||
|
||||
// extensions
|
||||
|
||||
/**
|
||||
@@ -817,6 +833,22 @@ public expect fun min(a: Float, b: Float): Float
|
||||
@SinceKotlin("1.2")
|
||||
public expect fun max(a: Float, b: Float): Float
|
||||
|
||||
|
||||
/**
|
||||
* Returns the cube root of [x]. For any `x`, `cbrt(-x) == -cbrt(x)`;
|
||||
* that is, the cube root of a negative value is the negative of the cube root
|
||||
* of that value's magnitude. Special cases:
|
||||
*
|
||||
* Special cases:
|
||||
* - If the argument is `NaN`, then the result is `NaN`.
|
||||
* - If the argument is infinite, then the result is an infinity with the same sign as the argument.
|
||||
* - If the argument is zero, then the result is a zero with the same sign as the argument.
|
||||
*/
|
||||
@SinceKotlin("1.7")
|
||||
@ExperimentalStdlibApi
|
||||
public expect fun cbrt(x: Float): Float
|
||||
|
||||
|
||||
// extensions
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user