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.math
object Main extends App {
val x: Double = -234
println(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 math package.
  • Line 4: We define the starting point x.
  • Line 5: We print x.
  • Line 6: We obtain the next value after x in the direction of negative infinity by invoking the nextUp() method. The value returned is stored in newNum.
  • Line 7: We printnewNum.
New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved