nextUp
Returns the Double value nearest to this value in a direction of positive infinity.
Special cases:
NaN.nextUp() isNaN`Double.POSITIVE_INFINITY.nextUp() is+Infinity`0.0.nextUp()isDouble.MIN_VALUE
Since Kotlin
1.2See also
Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
// Floating point numbers have discrete representation,
// so depending on the value's magnitude, the step towards
// the next representable value will be different
println(10000.0.nextUp()) // 10000.000000000002
println(100000.0.nextUp()) // 100000.00000000001
// -Infinity is any value large enough to no longer fit Double,
// so the next value after it towards 0.0 is -Double.MAX_VALUE
println("Double.NEGATIVE_INFINITY.nextUp() == -Double.MAX_VALUE is ${Double.NEGATIVE_INFINITY.nextUp() == -Double.MAX_VALUE}") // true
// For 0.0, the next value is the Double.MIN_VALUE, the smallest representable Double value
println("0.0.nextUp() == Double.MIN_VALUE is ${0.0.nextUp() == Double.MIN_VALUE}") // true
// special cases
println(Double.NaN.nextUp()) // NaN
println(Double.POSITIVE_INFINITY.nextUp()) // Infinity
//sampleEnd
}import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
// Unlike true real numbers, Double can only represent a fixed set of discrete values.
// According to IEEE-754, Double uses a single bit for a sign, 11 bits for the exponent, and 52 for the fraction.
// The bigger the integer part of the floating point value, the less space remains for "fitting" fractional part.
// As a result, starting from 2⁵² and until 2⁵³-1 Double values are incremented by 1.0
// (meaning that there are no in-between values), values from 2⁵³ until 2⁵⁴-1 are incremented by 2.0,
// but values in between 2⁵¹ and 2⁵²-1 are incremented by 0.5.
//
// The "distance" between a current value and the next one (the "increment" mentioned above) is dynamic,
// it depends on the magnitude of the current value, and it could be checked using Double.ulp.
val v2_52_53 = 4503599627370498.0 // value in range [2⁵², 2⁵³-1]
println(v2_52_53.ulp) // 1.0
val v2_53_54 = 9007199254740998.0 // value in range [2⁵³, 2⁵⁴-1]
println(v2_53_54.ulp) // 2.0
val v2_51_52 = 4503599627370490.0 // value in range [2⁵¹, 2⁵²-1]
println(v2_51_52.ulp) // 0.5
// Instead of using ulp, you can also check the next and previous values representable with a Double
// using Double.nextUp and Double.nextDown correspondingly.
println(9007199254740998.0.nextUp() - 9007199254740998.0) // 2.0
println(9007199254740998.0 - 9007199254740998.0.nextDown()) // 2.0
// As a more flexible alternative to nextUp/nextDown, one may use nextTowards, which accepts a value
// that works as a direction to increase/decrease a given value towards.
println(4503599627370496.0.nextTowards(Double.POSITIVE_INFINITY) - 4503599627370496.0) // 1.0
println(4503599627370496.0 - 4503599627370496.0.nextTowards(Double.NEGATIVE_INFINITY)) // 0.5
//sampleEnd
}Returns the Double value nearest to this value in a direction of positive infinity.
Special cases:
NaN.nextUp() isNaN`Double.POSITIVE_INFINITY.nextUp() is+Infinity`0.0.nextUp()isDouble.MIN_VALUE
Since Kotlin
1.2See also
Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
// Floating point numbers have discrete representation,
// so depending on the value's magnitude, the step towards
// the next representable value will be different
println(10000.0.nextUp()) // 10000.000000000002
println(100000.0.nextUp()) // 100000.00000000001
// -Infinity is any value large enough to no longer fit Double,
// so the next value after it towards 0.0 is -Double.MAX_VALUE
println("Double.NEGATIVE_INFINITY.nextUp() == -Double.MAX_VALUE is ${Double.NEGATIVE_INFINITY.nextUp() == -Double.MAX_VALUE}") // true
// For 0.0, the next value is the Double.MIN_VALUE, the smallest representable Double value
println("0.0.nextUp() == Double.MIN_VALUE is ${0.0.nextUp() == Double.MIN_VALUE}") // true
// special cases
println(Double.NaN.nextUp()) // NaN
println(Double.POSITIVE_INFINITY.nextUp()) // Infinity
//sampleEnd
}import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
// Unlike true real numbers, Double can only represent a fixed set of discrete values.
// According to IEEE-754, Double uses a single bit for a sign, 11 bits for the exponent, and 52 for the fraction.
// The bigger the integer part of the floating point value, the less space remains for "fitting" fractional part.
// As a result, starting from 2⁵² and until 2⁵³-1 Double values are incremented by 1.0
// (meaning that there are no in-between values), values from 2⁵³ until 2⁵⁴-1 are incremented by 2.0,
// but values in between 2⁵¹ and 2⁵²-1 are incremented by 0.5.
//
// The "distance" between a current value and the next one (the "increment" mentioned above) is dynamic,
// it depends on the magnitude of the current value, and it could be checked using Double.ulp.
val v2_52_53 = 4503599627370498.0 // value in range [2⁵², 2⁵³-1]
println(v2_52_53.ulp) // 1.0
val v2_53_54 = 9007199254740998.0 // value in range [2⁵³, 2⁵⁴-1]
println(v2_53_54.ulp) // 2.0
val v2_51_52 = 4503599627370490.0 // value in range [2⁵¹, 2⁵²-1]
println(v2_51_52.ulp) // 0.5
// Instead of using ulp, you can also check the next and previous values representable with a Double
// using Double.nextUp and Double.nextDown correspondingly.
println(9007199254740998.0.nextUp() - 9007199254740998.0) // 2.0
println(9007199254740998.0 - 9007199254740998.0.nextDown()) // 2.0
// As a more flexible alternative to nextUp/nextDown, one may use nextTowards, which accepts a value
// that works as a direction to increase/decrease a given value towards.
println(4503599627370496.0.nextTowards(Double.POSITIVE_INFINITY) - 4503599627370496.0) // 1.0
println(4503599627370496.0 - 4503599627370496.0.nextTowards(Double.NEGATIVE_INFINITY)) // 0.5
//sampleEnd
}Returns the Float value nearest to this value in a direction of positive infinity.
Special cases:
NaN.nextUp() isNaN`Float.POSITIVE_INFINITY.nextUp() is+Infinity`0.0f.nextUp()isFloat.MIN_VALUE
Since Kotlin
1.2See also
Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
// Floating point numbers have discrete representation,
// so depending on the value's magnitude, the step towards
// the next representable value will be different
println(10000.0f.nextUp()) // 10000.001
println(100000.0f.nextUp()) // 100000.01
// -Infinity is any value large enough to no longer fit Float,
// so the next value after it towards 0.0 is -Float.MAX_VALUE
println("Float.NEGATIVE_INFINITY.nextUp() == -Float.MAX_VALUE is ${Float.NEGATIVE_INFINITY.nextUp() == -Float.MAX_VALUE}") // true
// For 0.0, the next value is the Float.MIN_VALUE, the smallest representable Float value
println("0.0f.nextUp() == Float.MIN_VALUE is ${0.0f.nextUp() == Float.MIN_VALUE}") // true
// special cases
println(Float.NaN.nextUp()) // NaN
println(Float.POSITIVE_INFINITY.nextUp()) // Infinity
//sampleEnd
}import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
// Unlike true real numbers, Float can only represent a fixed set of discrete values.
// According to IEEE-754, Double uses a single bit for a sign, 8 bits for the exponent, and 23 for the fraction.
// The bigger the integer part of the floating point value, the less space remains for "fitting" fractional part.
// As a result, starting from 2²³ and until 2²⁴-1 Float values are incremented by 1.0
// (meaning that there are no in-between values), values from 2²³ until 2²⁵-1 are incremented by 2.0,
// but values in between 2²² and 2²³-1 are incremented by 0.5.
//
// The "distance" between a current value and the next one (the "increment" mentioned above) is dynamic,
// it depends on the magnitude of the current value, and it could be checked using Double.ulp.
val v2_23_24 = 8388618.0f // value in range [2²³, 2²⁴-1]
println(v2_23_24.ulp) // 1.0
val v2_24_25 = 16777226.0f // value in range [2²⁴, 2²⁵-1]
println(v2_24_25.ulp) // 2.0
val v2_22_23 = 4194306.0f // value in range [2²², 2²³-1]
println(v2_22_23.ulp) // 0.5
// Instead of using ulp, you can also check the next and previous values representable with a Double
// using Double.nextUp and Double.nextDown correspondingly.
println(16777226.0f.nextUp() - 16777226.0f) // 2.0
println(16777226.0f - 16777226.0f.nextDown()) // 2.0
// As a more flexible alternative to nextUp/nextDown, one may use nextTowards, which accepts a value
// that works as a direction to increase/decrease a given value towards.
println(8388608.0f.nextTowards(Float.POSITIVE_INFINITY) - 8388608.0f) // 1.0
println(8388608.0f - 8388608.0f.nextTowards(Float.NEGATIVE_INFINITY)) // 0.5
//sampleEnd
}Returns the Double value nearest to this value in a direction of positive infinity.
Special cases:
NaN.nextUp() isNaN`Double.POSITIVE_INFINITY.nextUp() is+Infinity`0.0.nextUp()isDouble.MIN_VALUE
Since Kotlin
1.2See also
Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
// Floating point numbers have discrete representation,
// so depending on the value's magnitude, the step towards
// the next representable value will be different
println(10000.0.nextUp()) // 10000.000000000002
println(100000.0.nextUp()) // 100000.00000000001
// -Infinity is any value large enough to no longer fit Double,
// so the next value after it towards 0.0 is -Double.MAX_VALUE
println("Double.NEGATIVE_INFINITY.nextUp() == -Double.MAX_VALUE is ${Double.NEGATIVE_INFINITY.nextUp() == -Double.MAX_VALUE}") // true
// For 0.0, the next value is the Double.MIN_VALUE, the smallest representable Double value
println("0.0.nextUp() == Double.MIN_VALUE is ${0.0.nextUp() == Double.MIN_VALUE}") // true
// special cases
println(Double.NaN.nextUp()) // NaN
println(Double.POSITIVE_INFINITY.nextUp()) // Infinity
//sampleEnd
}import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
// Unlike true real numbers, Double can only represent a fixed set of discrete values.
// According to IEEE-754, Double uses a single bit for a sign, 11 bits for the exponent, and 52 for the fraction.
// The bigger the integer part of the floating point value, the less space remains for "fitting" fractional part.
// As a result, starting from 2⁵² and until 2⁵³-1 Double values are incremented by 1.0
// (meaning that there are no in-between values), values from 2⁵³ until 2⁵⁴-1 are incremented by 2.0,
// but values in between 2⁵¹ and 2⁵²-1 are incremented by 0.5.
//
// The "distance" between a current value and the next one (the "increment" mentioned above) is dynamic,
// it depends on the magnitude of the current value, and it could be checked using Double.ulp.
val v2_52_53 = 4503599627370498.0 // value in range [2⁵², 2⁵³-1]
println(v2_52_53.ulp) // 1.0
val v2_53_54 = 9007199254740998.0 // value in range [2⁵³, 2⁵⁴-1]
println(v2_53_54.ulp) // 2.0
val v2_51_52 = 4503599627370490.0 // value in range [2⁵¹, 2⁵²-1]
println(v2_51_52.ulp) // 0.5
// Instead of using ulp, you can also check the next and previous values representable with a Double
// using Double.nextUp and Double.nextDown correspondingly.
println(9007199254740998.0.nextUp() - 9007199254740998.0) // 2.0
println(9007199254740998.0 - 9007199254740998.0.nextDown()) // 2.0
// As a more flexible alternative to nextUp/nextDown, one may use nextTowards, which accepts a value
// that works as a direction to increase/decrease a given value towards.
println(4503599627370496.0.nextTowards(Double.POSITIVE_INFINITY) - 4503599627370496.0) // 1.0
println(4503599627370496.0 - 4503599627370496.0.nextTowards(Double.NEGATIVE_INFINITY)) // 0.5
//sampleEnd
}Returns the Float value nearest to this value in a direction of positive infinity.
Special cases:
NaN.nextUp() isNaN`Float.POSITIVE_INFINITY.nextUp() is+Infinity`0.0f.nextUp()isFloat.MIN_VALUE
Since Kotlin
1.3See also
Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
// Floating point numbers have discrete representation,
// so depending on the value's magnitude, the step towards
// the next representable value will be different
println(10000.0f.nextUp()) // 10000.001
println(100000.0f.nextUp()) // 100000.01
// -Infinity is any value large enough to no longer fit Float,
// so the next value after it towards 0.0 is -Float.MAX_VALUE
println("Float.NEGATIVE_INFINITY.nextUp() == -Float.MAX_VALUE is ${Float.NEGATIVE_INFINITY.nextUp() == -Float.MAX_VALUE}") // true
// For 0.0, the next value is the Float.MIN_VALUE, the smallest representable Float value
println("0.0f.nextUp() == Float.MIN_VALUE is ${0.0f.nextUp() == Float.MIN_VALUE}") // true
// special cases
println(Float.NaN.nextUp()) // NaN
println(Float.POSITIVE_INFINITY.nextUp()) // Infinity
//sampleEnd
}import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
// Unlike true real numbers, Float can only represent a fixed set of discrete values.
// According to IEEE-754, Double uses a single bit for a sign, 8 bits for the exponent, and 23 for the fraction.
// The bigger the integer part of the floating point value, the less space remains for "fitting" fractional part.
// As a result, starting from 2²³ and until 2²⁴-1 Float values are incremented by 1.0
// (meaning that there are no in-between values), values from 2²³ until 2²⁵-1 are incremented by 2.0,
// but values in between 2²² and 2²³-1 are incremented by 0.5.
//
// The "distance" between a current value and the next one (the "increment" mentioned above) is dynamic,
// it depends on the magnitude of the current value, and it could be checked using Double.ulp.
val v2_23_24 = 8388618.0f // value in range [2²³, 2²⁴-1]
println(v2_23_24.ulp) // 1.0
val v2_24_25 = 16777226.0f // value in range [2²⁴, 2²⁵-1]
println(v2_24_25.ulp) // 2.0
val v2_22_23 = 4194306.0f // value in range [2²², 2²³-1]
println(v2_22_23.ulp) // 0.5
// Instead of using ulp, you can also check the next and previous values representable with a Double
// using Double.nextUp and Double.nextDown correspondingly.
println(16777226.0f.nextUp() - 16777226.0f) // 2.0
println(16777226.0f - 16777226.0f.nextDown()) // 2.0
// As a more flexible alternative to nextUp/nextDown, one may use nextTowards, which accepts a value
// that works as a direction to increase/decrease a given value towards.
println(8388608.0f.nextTowards(Float.POSITIVE_INFINITY) - 8388608.0f) // 1.0
println(8388608.0f - 8388608.0f.nextTowards(Float.NEGATIVE_INFINITY)) // 0.5
//sampleEnd
}Returns the Double value nearest to this value in a direction of positive infinity.
Special cases:
NaN.nextUp() isNaN`Double.POSITIVE_INFINITY.nextUp() is+Infinity`0.0.nextUp()isDouble.MIN_VALUE
Since Kotlin
1.3See also
Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
// Floating point numbers have discrete representation,
// so depending on the value's magnitude, the step towards
// the next representable value will be different
println(10000.0.nextUp()) // 10000.000000000002
println(100000.0.nextUp()) // 100000.00000000001
// -Infinity is any value large enough to no longer fit Double,
// so the next value after it towards 0.0 is -Double.MAX_VALUE
println("Double.NEGATIVE_INFINITY.nextUp() == -Double.MAX_VALUE is ${Double.NEGATIVE_INFINITY.nextUp() == -Double.MAX_VALUE}") // true
// For 0.0, the next value is the Double.MIN_VALUE, the smallest representable Double value
println("0.0.nextUp() == Double.MIN_VALUE is ${0.0.nextUp() == Double.MIN_VALUE}") // true
// special cases
println(Double.NaN.nextUp()) // NaN
println(Double.POSITIVE_INFINITY.nextUp()) // Infinity
//sampleEnd
}import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
// Unlike true real numbers, Double can only represent a fixed set of discrete values.
// According to IEEE-754, Double uses a single bit for a sign, 11 bits for the exponent, and 52 for the fraction.
// The bigger the integer part of the floating point value, the less space remains for "fitting" fractional part.
// As a result, starting from 2⁵² and until 2⁵³-1 Double values are incremented by 1.0
// (meaning that there are no in-between values), values from 2⁵³ until 2⁵⁴-1 are incremented by 2.0,
// but values in between 2⁵¹ and 2⁵²-1 are incremented by 0.5.
//
// The "distance" between a current value and the next one (the "increment" mentioned above) is dynamic,
// it depends on the magnitude of the current value, and it could be checked using Double.ulp.
val v2_52_53 = 4503599627370498.0 // value in range [2⁵², 2⁵³-1]
println(v2_52_53.ulp) // 1.0
val v2_53_54 = 9007199254740998.0 // value in range [2⁵³, 2⁵⁴-1]
println(v2_53_54.ulp) // 2.0
val v2_51_52 = 4503599627370490.0 // value in range [2⁵¹, 2⁵²-1]
println(v2_51_52.ulp) // 0.5
// Instead of using ulp, you can also check the next and previous values representable with a Double
// using Double.nextUp and Double.nextDown correspondingly.
println(9007199254740998.0.nextUp() - 9007199254740998.0) // 2.0
println(9007199254740998.0 - 9007199254740998.0.nextDown()) // 2.0
// As a more flexible alternative to nextUp/nextDown, one may use nextTowards, which accepts a value
// that works as a direction to increase/decrease a given value towards.
println(4503599627370496.0.nextTowards(Double.POSITIVE_INFINITY) - 4503599627370496.0) // 1.0
println(4503599627370496.0 - 4503599627370496.0.nextTowards(Double.NEGATIVE_INFINITY)) // 0.5
//sampleEnd
}Returns the Double value nearest to this value in a direction of positive infinity.
Special cases:
NaN.nextUp() isNaN`Double.POSITIVE_INFINITY.nextUp() is+Infinity`0.0.nextUp()isDouble.MIN_VALUE
Since Kotlin
1.8See also
Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
// Floating point numbers have discrete representation,
// so depending on the value's magnitude, the step towards
// the next representable value will be different
println(10000.0.nextUp()) // 10000.000000000002
println(100000.0.nextUp()) // 100000.00000000001
// -Infinity is any value large enough to no longer fit Double,
// so the next value after it towards 0.0 is -Double.MAX_VALUE
println("Double.NEGATIVE_INFINITY.nextUp() == -Double.MAX_VALUE is ${Double.NEGATIVE_INFINITY.nextUp() == -Double.MAX_VALUE}") // true
// For 0.0, the next value is the Double.MIN_VALUE, the smallest representable Double value
println("0.0.nextUp() == Double.MIN_VALUE is ${0.0.nextUp() == Double.MIN_VALUE}") // true
// special cases
println(Double.NaN.nextUp()) // NaN
println(Double.POSITIVE_INFINITY.nextUp()) // Infinity
//sampleEnd
}import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
// Unlike true real numbers, Double can only represent a fixed set of discrete values.
// According to IEEE-754, Double uses a single bit for a sign, 11 bits for the exponent, and 52 for the fraction.
// The bigger the integer part of the floating point value, the less space remains for "fitting" fractional part.
// As a result, starting from 2⁵² and until 2⁵³-1 Double values are incremented by 1.0
// (meaning that there are no in-between values), values from 2⁵³ until 2⁵⁴-1 are incremented by 2.0,
// but values in between 2⁵¹ and 2⁵²-1 are incremented by 0.5.
//
// The "distance" between a current value and the next one (the "increment" mentioned above) is dynamic,
// it depends on the magnitude of the current value, and it could be checked using Double.ulp.
val v2_52_53 = 4503599627370498.0 // value in range [2⁵², 2⁵³-1]
println(v2_52_53.ulp) // 1.0
val v2_53_54 = 9007199254740998.0 // value in range [2⁵³, 2⁵⁴-1]
println(v2_53_54.ulp) // 2.0
val v2_51_52 = 4503599627370490.0 // value in range [2⁵¹, 2⁵²-1]
println(v2_51_52.ulp) // 0.5
// Instead of using ulp, you can also check the next and previous values representable with a Double
// using Double.nextUp and Double.nextDown correspondingly.
println(9007199254740998.0.nextUp() - 9007199254740998.0) // 2.0
println(9007199254740998.0 - 9007199254740998.0.nextDown()) // 2.0
// As a more flexible alternative to nextUp/nextDown, one may use nextTowards, which accepts a value
// that works as a direction to increase/decrease a given value towards.
println(4503599627370496.0.nextTowards(Double.POSITIVE_INFINITY) - 4503599627370496.0) // 1.0
println(4503599627370496.0 - 4503599627370496.0.nextTowards(Double.NEGATIVE_INFINITY)) // 0.5
//sampleEnd
}Returns the Double value nearest to this value in a direction of positive infinity.
Special cases:
NaN.nextUp() isNaN`Double.POSITIVE_INFINITY.nextUp() is+Infinity`0.0.nextUp()isDouble.MIN_VALUE
Since Kotlin
1.8See also
Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
// Floating point numbers have discrete representation,
// so depending on the value's magnitude, the step towards
// the next representable value will be different
println(10000.0.nextUp()) // 10000.000000000002
println(100000.0.nextUp()) // 100000.00000000001
// -Infinity is any value large enough to no longer fit Double,
// so the next value after it towards 0.0 is -Double.MAX_VALUE
println("Double.NEGATIVE_INFINITY.nextUp() == -Double.MAX_VALUE is ${Double.NEGATIVE_INFINITY.nextUp() == -Double.MAX_VALUE}") // true
// For 0.0, the next value is the Double.MIN_VALUE, the smallest representable Double value
println("0.0.nextUp() == Double.MIN_VALUE is ${0.0.nextUp() == Double.MIN_VALUE}") // true
// special cases
println(Double.NaN.nextUp()) // NaN
println(Double.POSITIVE_INFINITY.nextUp()) // Infinity
//sampleEnd
}import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
// Unlike true real numbers, Double can only represent a fixed set of discrete values.
// According to IEEE-754, Double uses a single bit for a sign, 11 bits for the exponent, and 52 for the fraction.
// The bigger the integer part of the floating point value, the less space remains for "fitting" fractional part.
// As a result, starting from 2⁵² and until 2⁵³-1 Double values are incremented by 1.0
// (meaning that there are no in-between values), values from 2⁵³ until 2⁵⁴-1 are incremented by 2.0,
// but values in between 2⁵¹ and 2⁵²-1 are incremented by 0.5.
//
// The "distance" between a current value and the next one (the "increment" mentioned above) is dynamic,
// it depends on the magnitude of the current value, and it could be checked using Double.ulp.
val v2_52_53 = 4503599627370498.0 // value in range [2⁵², 2⁵³-1]
println(v2_52_53.ulp) // 1.0
val v2_53_54 = 9007199254740998.0 // value in range [2⁵³, 2⁵⁴-1]
println(v2_53_54.ulp) // 2.0
val v2_51_52 = 4503599627370490.0 // value in range [2⁵¹, 2⁵²-1]
println(v2_51_52.ulp) // 0.5
// Instead of using ulp, you can also check the next and previous values representable with a Double
// using Double.nextUp and Double.nextDown correspondingly.
println(9007199254740998.0.nextUp() - 9007199254740998.0) // 2.0
println(9007199254740998.0 - 9007199254740998.0.nextDown()) // 2.0
// As a more flexible alternative to nextUp/nextDown, one may use nextTowards, which accepts a value
// that works as a direction to increase/decrease a given value towards.
println(4503599627370496.0.nextTowards(Double.POSITIVE_INFINITY) - 4503599627370496.0) // 1.0
println(4503599627370496.0 - 4503599627370496.0.nextTowards(Double.NEGATIVE_INFINITY)) // 0.5
//sampleEnd
}