What is nextUp() in Scala?
Overview
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 positive infinity.
Scala internally uses Java implementations of the corresponding methods. This method internally invokes nextUp() method in Java.
Syntax
math.nextUp(x)
Parameters
x: The starting floating point or a double number.
Return value
The method returns the nearest floating-point/double number in the direction of positive infinity adjacent to the given number.
Example
import scala.mathobject Main extends App {val x: Double = 43.12println(s"starting point - ${x}")val newNum = Math.nextUp(x)println(s"Number adjacent to ${x} towards positive infinity - ${newNum}")}
Explanation
- Line 6: The following value after
xin the direction of positive infinity is obtained by invoking thenextUp()method. The value returned is stored innewNum. - Line 7: Print the
newNum.
Free Resources
Copyright ©2026 Educative, Inc. All rights reserved