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.math
object Main extends App {
val x: Double = 43.12
println(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 x in the direction of positive infinity is obtained by invoking the nextUp() method. The value returned is stored in newNum.
  • Line 7: Print the newNum.
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