Library contents

Kotlin java.lang.Math.nextUp

Move to the next representable floating-point value toward positive infinity.

A simple example

java.lang.Math.nextUp

  1. Start with 1.0
  2. Do this Take one double-precision step upward
  3. Result 1.0000000000000002
The result is the closest representable double above 1.0.
Lesson.kt
fun main() {
    println(java.lang.Math.nextUp(1.0))
}
Output
1.0000000000000002

Syntax

Kotlin syntax
java.lang.Math.nextUp(limit)
Run these examples in Kotlin

Save one example at a time as Lesson.kt. Use Kotlin 2.2 on JDK 21.

kotlinc Lesson.kt -include-runtime -d lesson.jar
java -jar lesson.jar

Test just above a measurement limit

A calibration routine needs to test the nearest representable value on one side of a limit. Move by one floating-point step so the boundary test uses a value the computer can actually store.

From the programval limit = 1.0
Result1.0000000000000002
Lesson.kt

fun main() {
    val limit = 1.0
    println(java.lang.Math.nextUp(limit))
}
Output
1.0000000000000002

The printed value is the closest double greater than one. It is useful for testing a strict upper boundary.

Advertisements

Test the scale just above 2

A scale switches display ranges at 2. The tester needs the nearest representable double above this threshold to exercise the boundary.

Given2.0 · one step above
Worked result2.0000000000000004

There is no intervening double between the threshold and this result.

Test the exposure meter just above 8

A exposure meter switches display ranges at 8. The tester needs the nearest representable double above this threshold to exercise the boundary.

Given8.0 · one step above
Worked result8.000000000000002

There is no intervening double between the threshold and this result.

What to watch for

The step is a representation limit, not a fixed engineering tolerance.

Documentation for java.lang.Math.nextUp