What is nextDown() 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 negative infinity.
Scala internally uses Java implementations of the corresponding methods. This method internally invokes the nextDown() method in Java.
Syntax
math.nextDown(x)
Parameters
x: It is the starting floating point or a double number.
Return value
This method returns the nearest floating-point/double number in the direction of negative infinity adjacent to the given number.
Code example
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}")}
Code explanation
- Line 1: We import the
mathpackage. - Line 4: We define the starting point
x. - Line 5: We print
x. - Line 6: We obtain the next value after
xin the direction of negative infinity by invoking thenextUp()method. The value returned is stored innewNum. - Line 7: We print
newNum.
Free Resources
Copyright ©2026 Educative, Inc. All rights reserved