Implement in JS nextUp(), nextDown(), nextTowards() and ulp extensions

#KT-4900
This commit is contained in:
Ilya Gorbunov
2017-08-31 22:12:08 +03:00
parent 480d4a0093
commit aa3bfc55c3
6 changed files with 138 additions and 37 deletions
@@ -428,6 +428,41 @@ public expect fun Double.withSign(sign: Double): Double
@SinceKotlin("1.2")
public expect fun Double.withSign(sign: Int): Double
/**
* Returns the ulp (unit in the last place) of this value.
*
* An ulp is a positive distance between this value and the next nearest [Double] value larger in magnitude.
*
* Special Cases:
* - `NaN.ulp` is `NaN`
* - `x.ulp` is `+Inf` when `x` is `+Inf` or `-Inf`
* - `0.0.ulp` is `Double.MIN_VALUE`
*/
@SinceKotlin("1.2")
public expect val Double.ulp: Double
/**
* Returns the [Double] value nearest to this value in direction of positive infinity.
*/
@SinceKotlin("1.2")
public expect fun Double.nextUp(): Double
/**
* Returns the [Double] value nearest to this value in direction of negative infinity.
*/
@SinceKotlin("1.2")
public expect fun Double.nextDown(): Double
/**
* Returns the [Double] value nearest to this value in direction from this value towards the value [to].
*
* Special cases:
* - `x.nextTowards(y)` is `NaN` if either `x` or `y` are `NaN`
* - `x.nextTowards(x) == x`
*
*/
@SinceKotlin("1.2")
public expect fun Double.nextTowards(to: Double): Double
/**
* Rounds this [Double] value to the nearest integer and converts the result to [Int].
* Ties are rounded towards positive infinity.