Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

scala

What is nextDown() in scala?

Abhilash

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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}")
}
nextDown() method in scala

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.

RELATED TAGS

scala

CONTRIBUTOR

Abhilash
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring