The nextUp()
method is a static method in the math
package that returns the floating point number adjacent to the first argument towards the direction of the negative infinity.
Scala internally uses Java implementations of the corresponding methods. This method internally invokes the nextDown() method in Java.
math.nextDown(x)
x
: It is the starting floating point or a double number.This method returns the nearest floating-point/double number in the direction of negative infinity adjacent to the given number.
Let’s look at the code below:
import scala.mathobject Main extends App {val x: Double = -234println(s"starting point - ${x}")val newNum = Math.nextDown(x)println(s"Number adjacent to ${x} towards negative infinity - ${newNum}")}
math
package.x
.x
.x
in the direction of negative infinity by invoking the nextUp()
method. The value returned is stored in newNum
.newNum
.Free Resources