Rename sgn to sign, add docs and tests

#KT-4900
This commit is contained in:
Ilya Gorbunov
2017-07-25 07:17:16 +03:00
parent d0b12e3872
commit 805d1c90b7
3 changed files with 164 additions and 11 deletions
+45 -2
View File
@@ -317,13 +317,25 @@ public inline fun round(a: Double): Double = nativeMath.rint(a)
/**
* Returns the absolute value of the given value [a].
*
* Special cases:
* - `abs(NaN)` is `NaN`
*
* @see absoluteValue extension property for [Double]
*/
@InlineOnly
public inline fun abs(a: Double): Double = nativeMath.abs(a)
// also as extension val [sign]
/**
* Returns the sign of the given value [a]:
* - `-1.0` if the value is negative,
* - zero if the value is zero,
* - `1.0` if the value is positive
*
* Special case:
* - `sign(NaN)` is `NaN`
*/
@InlineOnly
public inline fun sgn(a: Double): Double = nativeMath.signum(a)
public inline fun sign(a: Double): Double = nativeMath.signum(a)
@@ -364,10 +376,41 @@ public inline fun Double.pow(other: Int): Double = nativeMath.pow(this, other.to
public inline fun Double.IEEErem(other: Double): Double = nativeMath.IEEEremainder(this, other)
/**
* Returns the absolute value of this value.
*
* Special cases:
* - `NaN.absoluteValue` is `NaN`
*
* @see abs function
*/
@InlineOnly
public inline val Double.absoluteValue: Double get() = nativeMath.abs(this)
/**
* Returns the sign of this value:
* - `-1.0` if the value is negative,
* - zero if the value is zero,
* - `1.0` if the value is positive
*
* Special case:
* - `NaN.sign` is `NaN`
*/
@InlineOnly
public inline val Double.sign: Double get() = nativeMath.signum(this)
/**
* Returns this value with the sign bit same as of the [sign] value.
*
* If [sign] is `NaN` the sign of the result is undefined.
*/
@InlineOnly
public inline fun Double.withSign(sign: Double): Double = nativeMath.copySign(this, sign)
/**
* Returns this value with the sign bit same as of the [sign] value.
*/
@InlineOnly
public inline fun Double.withSign(sign: Int): Double = nativeMath.copySign(this, sign.toDouble())
public inline val Double.ulp: Double get() = nativeMath.ulp(this)