GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Java Tutorial
  • Advanced Java
  • Interview Questions
  • Exercises
  • Examples
  • Quizzes
  • Projects
  • Cheatsheet
  • DSA in Java
  • Java Collection
  • Introduction3 min read
  • Variables2 min read
  • Data Types7 min read
  • Operators7 min read

This view

  • Original page
  • New address

GeezerVison is showing www.geeksforgeeks.org — Java Math nextDown() Method - GeeksforGeeks

geeksforgeeks
search icon
  • Courses
  • Tutorials
  • Interview Prep
  • Java Tutorial
  • Advanced Java
  • Interview Questions
  • Exercises
  • Examples
  • Quizzes
  • Projects
  • Cheatsheet
  • DSA in Java
  • Java Collection

Java Math nextDown() Method

Last Updated : 12 May, 2025

The nextDown() is a built-in Math function in Java that returns the next smaller floating-point number adjacent to the parameter provided in the direction of negative infinity. The nextDown() implementation may run faster than its equivalent nextAfter() call. The nextDown() method is overloaded which means that we have more than one method with the same name under the Math class. Two overloaded methods of the nextDown():

  • double type: nextDown(double d)
  • float type: nextDown(float f)

Syntax of nextDown() Method

public static double Math.nextDown(double d)

public static float Math.nextDown(float f)

  • Parameters: d or f: The floating-point number that is double or float, for which we want to find the next lower representable value.
  • Returns: It returns the adjacent floating-point value closer to negative infinity.

Special Values:

  • If the input is NaN, we will get result NaN.
  • If the input is 0.0, we will get the result as the smallest negative value representable, for example, -Double.MIN_VALUE or -Float.MIN_VALUE.
  • If the input is negative infinity, the result is also negative infinity.

Examples of Java Math nextDown() Method

Example 1: In this example, we will see how nextDown() method works in Java.

Java
// Java program to demonstrate Math.nextDown() method
import java.lang.Math;

public class Geeks {
    public static void main(String[] args) {
        double x = 50.5;
        float y = 19.2f;

        System.out.println("Next down of 50.5 (double): " + Math.nextDown(x));
        System.out.println("Next down of 19.2f (float): " + Math.nextDown(y));
    }
}

Output
Next down of 50.5 (double): 50.49999999999999
Next down of 19.2f (float): 19.199999


Example 2: In this example, we are going to try with special values like NaN, 0.0, and negative infinity.

Java
// Java program to demonstrate nextDown() 
// with special floating-point values
import java.lang.Math;

public class Geeks {
    
    public static void main(String[] args) {
        
        System.out.println("Next down of NaN: " + Math.nextDown(Double.NaN));
        System.out.println("Next down of 0.0f: " + Math.nextDown(0.0f));
        System.out.println("Next down of -Infinity: " + Math.nextDown(Double.NEGATIVE_INFINITY));
    }
}

Output
Next down of NaN: NaN
Next down of 0.0f: -1.4E-45
Next down of -Infinity: -Infinity


Important Points:

  • This method works with both float and double.
  • It returns the closest representable value which is smaller than the input.
  • This method id useful for numeriacal methods or any kind of comparison operations.
Comment

Explore

    Basics
    • Introduction3 min read
    • Variables2 min read
    • Data Types7 min read
    • Operators7 min read
    • Decision Making5 min read
    • Methods7 min read
    • Arrays7 min read
    • Strings5 min read
    OOP & Interface
    • Introduction6 min read
    • Constructors6 min read
    • Encapsulation3 min read
    • Inheritance8 min read
    • Polymorphism5 min read
    • Abstraction5 min read
    • Interfaces8 min read
    Collections
    • Collection class9 min read
    • Collection Interface5 min read
    • List Interface8 min read
    • Set Interface5 min read
    • Queue Interface5 min read
    • Map Interface in Java6 min read
    • Iterator4 min read
    Advance Java Concepts
    • Exception handling6 min read
    • Java Multithreading Tutorial3 min read
    • Synchronization in Java9 min read
    • File handling6 min read
    • Method References3 min read
    • Java 8 Stream Tutorial7 min read
    • Memory Management4 min read
    • Garbage Collection in Java6 min read
    • Networking6 min read
    • JDBC5 min read
    Practice Java
    • Interview Questions15+ min read
    • Programs6 min read
    • Practice Problems5 min read
    • Quiz1 min read
    • Project Ideas15+ min read
    Courses
    • Java Backend Course2 min read
    • Placement 360 Course2 min read
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.