Java .nextDown()
Anonymous contributor
Published Oct 21, 2022
Contribute to Docs
The Math.nextDown() method returns the floating-point value adjacent to the parameter provided in the direction of negative infinity.
Syntax
Math.nextDown(x)
- The
xparameter can be of typedoubleorfloat. - The return type is of
doubleorfloat. - Though it is the opposite of
.nextAfter(), the.nextDown()method is semantically equivalent tonextAfter(d, Double.NEGATIVE_INFINITY);ornextAfter(f, Float.NEGATIVE_INFINITY);.
Note: A
.nextDown()implementation may run faster than its equivalent.nextAfter()call.
Special cases include the following:
- If
xisNaN, the result isNaN. - If
xis negative infinity, the result is negative infinity. - If
xis zero, the result is-Double.MIN_VALUEor-Float.MIN_VALUE.
Example
The following is an example of the .nextDown() method:
// Test.javapublic class Test {public static void main(String args[]) {double d = 23.44;System.out.println(Math.nextDown(d));}}
This results in the following output:
23.439999999999998
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Java on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- Learn to code in Java — a robust programming language used to create software, web and mobile apps, and more.
- Beginner Friendly.17 hours