×

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

Design of JDBC

Java applications may interface using database systems from many vendors using the Java Database Connectivity (JDBC) Application Software Interface (API) from Sun Microsystem. To connect spreadsheets, JDBC and database drivers...

3 minutes read.

Java Output Formatting

Sometimes we want a program's output to be displayed in a specific format. The printf () function in the C programming language can be used to achieve this. We will...

4 minutes read.

Stock Span Problem Using Stack in Java

The stock span problem is an issue in finance where we must determine a stock’s price span over all N days given a set of N daily price quotes. The...

6 minutes read.

Java Comparable Interface

We implement comparable interface when we need a new logic for determining equality. if two objects are equal, the equals() method returns true and compareTo() method returns 0. The basic...

1 minute read.

Java Boyer Moore

A string searching or matching technique called the Boyer-Moore algorithm was created in 1977 by Robert S. Boyer and J. Strother Moore. It is the most popular and effective string-matching...

9 minutes read.

Java String concat() method:

Java String concat() method is used to add the given String to the end of the current String. Syntax: public String concat(String str) Parameter: Str: String to be concatenated at the end of current...

1 minute read.

Order of Execution of Constructors in Java Inheritance

Constructor in Java There are several distinctions between a method and a function object() in Java. The name of the function object()  is identical to the class name. There is no...

4 minutes read.

How annotations work in Java

Annotations were introduced by sun microsystem and are available from the java 1.5 version. In general, configurations can be done either by XML or by annotations. Hibernate and spring framework users prefer...

4 minutes read.

Example of Static import in Java

Static keyword Java's static keyword is mainly used to control memory. Variables, methods, blocks, and nested classes are compatible with the static keyword. Instead of an instance, the static keyword is...

3 minutes read.

Java Integer highestOneBit()

The highestOneBit() method of Java Integer class returns an int value with at most a single one-bit, in the position of the highest-order one-bit in the specified int value.  Syntax public static...

1 minute read.

Bouncy Number in Java

We will define bouncy numbers in this section and write Java programmes to determine whether a specific number is bouncy. Java coding exams and academic assignments usually inquire about the...

3 minutes read.

Java Protected Keyword

An access modifier is a keyword that Java protects. It can be used to constructors, methods, inner classes, and variables. Variables, methods, and constructors that have been marked protected in...

3 minutes read.

Constructor Overloading in Java

In Java, constructors can be overloaded just like methods. The idea of having multiple constructors with various parameter sets so that each function Object()  can carry out a particular task...

3 minutes read.

Java LinkedList vs ArrayList

LinkedList In LinkedList, each element is a distinct entity containing an information portion and an address component, and the elements are not kept in consecutive locations. Pointers & addresses are used...

3 minutes read.

Sphenic Number in Java

In this section, we will learn what is a sphenic number is and show you how to write Java programmes to determine if a specific number are sphenic or not....

3 minutes read.

Least Operator to Express Number in Java

In this article, we will learn about how to obtain a target number using a single number or a single integer by leveraging least operators in Java. There can be...

3 minutes read.

Java StringBuffer vs StringBuilder

Java StringBuffer vs StringBuilder StringBuffer The StringBuffer class is used to create mutable string. StringBuffer shows writable and growable character sequences. Java StringBuffer program FileName: StringBufferExample.java // A basic program that demonstrates the working...

2 minutes read.

&& Operator in Java

“ && ” is the conditional - And operator in Java. In Java, it is an example of a logical operator. In Java, the “ & ” operator has two...

3 minutes read.

Fall through in Java

In this article, you will be acknowledged about the fall through condition in Java along with an example program. Fall through It is a situation where there isn't a break statement in...

3 minutes read.

Economical number in Java

Economical number is said to be economically efficient if the number of digits after prime factorization of the original number with their powers is less than the number of digits...

3 minutes read.