Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

java
communitycreator

How to use nextDown() in Java

Fouzia Bashir

nextDown() is a built-in method of the java.lang.Math library. It returns the value adjacent to the n argument in the direction of negative infinity (-∞).

Syntax

The example below is used for primitive double type argument:


static double nextDown(double n)

The example below is used for primitive float type argument:


static float nextDown(float n)

Parameter

n can be a double or float value.

Return value

This function returns the value adjacent to n (double or float) in the direction of (-∞).

Special cases

  • If the parameter’s value is NaN, then the function will return NaN.
  • If we pass zero as an argument while dealing with type double, then this function will return Double.MIN_VALUE.
  • When we are dealing with float and the argument is zero,the result will be Float.MIN_VALUE.
  • If we pass negative infinity as an argument, then the return value will be negative infinity.

Code

public class EdPresso
{
    public static void main(String[] args) 
    {
        double y = 0.0;
        // the argument is zero, the return value is Double.MIN_VALUE
        System.out.println(Math.nextDown(y));

        y = 0.0/0;
        // the argument is NaN, the return value is NaN
        System.out.println(Math.nextDown(y));

        y = 865.78;
        // the argument is of type double, the return value is the adjacent double value in the direction of negative infinity
        System.out.println(Math.nextDown(y));

        y = -865.78;
        // the input of argument is zero, result: Float.MIN_VALUE
        System.out.println(Math.nextDown(y));
        
        float x = 0.0f;
        // the argument is zero, the return value is Float.MIN_VALUE
        System.out.println(Math.nextDown(x));
    }
}

RELATED TAGS

java
communitycreator
RELATED COURSES

View all Courses

Keep Exploring