×

Java Math nextDown() Method

The nextDown() method of Math class returns the floating-point number adjacent to the argument in direction of the negative infinity.

Syntax:

  1. public static double nextDown (double d)
  2. public static float nextDown (float f)

Parameters:

The parameters ‘d’ and ‘f’ represent the starting floating-point values.

Return Value:

The nextDown () method returns the floating-point number which is closer to negative infinity.

Special cases of the nextDown() method are as follows:

  • It returns NaN, is the argument passed is NaN.
  • It returns negative infinity, if the argument is negative infinity.
  • It returns –Double.MIN_VALUE, is the argument is zero.

Example 1:

public class JavaMathNextDownExample1 {
    public static void main(String[] args) {
        float f = 123.78f;
        // returns the floating-point number which is closer to negative infinity
        System.out.println("Floating-point number : "+Math.nextDown(f));
    }
}

Output:

Floating-point number : 123.77999

Example 2:

public class JavaMathNextDownExample2 {
    public static void main(String[] args) {
        Double d = -0d;
        // returns the floating-point number which is closer to negative infinity
        System.out.println("Floating-point number : "+Math.nextDown(d));
    }
}

Output:

Floating-point number : -4.9E-324

Example 3:

public class JavaMathNextDownExample3 {
    public static void main(String[] args) {
        Double d = Double.NaN;
        //returns NaN, is the argument passed is NaN.
        System.out.println("Floating-point number : "+Math.nextDown(d));
    }
}

Output:

Floating-point number : NaN

Example 4:

public class JavaMathNextDownExample4 {
    public static void main(String[] args) {
        Double d = Double.NEGATIVE_INFINITY;
        // returns negative infinity, if the argument is negative infinity
        System.out.println("Floating-point number : "+Math.nextDown(d));
    }
}

Output:

Floating-point number : -Infinity

Example 5:

public class JavaMathNextDownExample5 {
    public static void main(String[] args) {
        Double d = 0.0d;
        //returns –Double.MIN_VALUE, is the argument is zero.
        System.out.println("Floating-point number : "+Math.nextDown(d));
    }
}

Output:

Floating-point number : -4.9E-324

Related Topics

Shallow copy in Java

Java's most important task is making a copy or clone of an object. In this part, we'll talk about shallow copies in Java and how to make them of Java...

4 minutes read.

Java Program to Create Set of Pairs Using HashSet

HashSet in Java: HashSet is an assortment in Java that has a place with java.util bundle. It inside utilises HashMap to store components. It is an execution of the Set connection...

11 minutes read.

Bellman Ford Algorithm in Java

Numerous algorithms have been used in dynamic programming to determine the shortest path inside a graph. Among them are Floyd, all-pair shortest path problem, Breadth First Search, Depth First Search,...

6 minutes read.

How to resolve Illegal state exceptions in Java

What is IllegalStateException? When a method is called at the incorrect time, a runtime exception called an IllegalStateException is raised in Java. This exception is utilized to show that a method...

3 minutes read.

How to write basic Java Programs

Java Basic Programs In this section, we will learn how to write basic Java programs. But first we need to take care of the following requirement list. To execute a Java program,...

4 minutes read.

How to check the Java version in cmd

To make programs that can run on our systems, we need to install programming language-related software in our systems. Different programming languages require different types of software, aka IDEs (Integrated...

5 minutes read.

How to Develop Programming Logic in Java?

Introduction In the world of software development, Java programming language is one of the most powerful programming languages that is used to create a wide range of applications. It includes desktop,...

18 minutes read.

MessageDigest in Java

The compression of mathematical numbers is accomplished using hash functions. In almost every data security application, hash functions are employed. The hashing, often called has values, returns a value called...

3 minutes read.

String Manipulation in Java

String Manipulation in Java In Java, string manipulation is a common task performed by programmer. Java String class provides many built-in functions that are used to manipulate string. The manipulation of...

4 minutes read.

Java Abstraction

Java Abstraction Abstraction is an advanced feature of Java to make it transparent. The main motive behind the abstraction is to deal with ideas, not with events. Abstraction is a process...

4 minutes read.

Compare Two Times in Java

Definition The compareTo() function of the LocalTime class is used to compare times. The class's compareTo() method compares two LocalTime objects. Here we have two objects that have to be compared: the...

4 minutes read.

Sublime Number in Java

In this tutorial, we will understand what is meant by sublime number in java. From the point of the coding interview, it is one of the important topics. We will we will...

4 minutes read.

Callable Statement in Java

The Callable statement in Java is used to call the functions and Stored procedures. Example: If we want to know about the age of a person based on their date of birth,...

3 minutes read.

Java String Inbuilt functions

There are different types of inbuilt functions available in the Java String class, all of them are listed below. Char chat At (int index)It outputs the character indicated by the index....

5 minutes read.

POJO in Java

Plain old Java Object, in short, is called POJO in Java. POJO is an everyday object that is not subject to any specific limitations. We can use POJO in any Java...

3 minutes read.

Java Math random() Method

The random() method of Math class returns a double value with a positive sign, less than 1 and greater than or equal to 0.0. This method is properly synchronized with...

1 minute read.

XOR of Array Elements Except Itself in Java

A lot of the biggest IT organisations, including The Google, Amazon, TCS, and The Accenture, etc., question about this issue in their interview processes. By addressing the issue, one hopes to assess...

5 minutes read.

What is Core Java?

The fundamental Java, which includes the fundamental idea of the Java programming language, is referred to as "Core Java." The definition of "Core" is the core idea of something. Core...

3 minutes read.

Java OCR

In this article, you will be acknowledged about what is a tesseract OCR, how it works, what are its used and advantages and disadvantages. Also, you will be able to...

4 minutes read.

Java List Implementations

ArrayList and LinkedList are the two implementations of List that are for general-purpose. You'll probably utilise an array list the majority of the time because it's quick and provides constant-time...

3 minutes read.