Close

Java - Math.nextDown() Examples

Java Java API 


Class:

java.lang.Math

java.lang.Objectjava.lang.Objectjava.lang.Mathjava.lang.MathLogicBig

Methods:

public static double nextDown(double d)

Returns the floating-point value adjacent to d in the direction of negative infinity. This method is semantically equivalent to nextAfter(d, Double.NEGATIVE_INFINITY); however, a nextDown implementation may run faster than its equivalent nextAfter call.



public static float nextDown(float f)

Returns the floating-point value adjacent to f in the direction of negative infinity. This method is semantically equivalent to nextAfter(f, Float.NEGATIVE_INFINITY); however, a nextDown implementation may run faster than its equivalent nextAfter call.


Examples


package com.logicbig.example.math;

public class NextDownExample {

public static void main(String... args) {
findNextDown(23.5);
findNextDown(576.127);
findNextDown(-11);
findNextDown(0.0);
findNextDown(0.0 / 0);
findNextDown(Double.MIN_VALUE);
findNextDown(Double.NEGATIVE_INFINITY);
}

private static void findNextDown(double d) {
double nextDown = Math.nextDown(d);
System.out.printf("Math.nextDown(%s) = %s%n", d, nextDown);
}
}

Output

Math.nextDown(23.5) = 23.499999999999996
Math.nextDown(576.127) = 576.1269999999998
Math.nextDown(-11.0) = -11.000000000000002
Math.nextDown(0.0) = -4.9E-324
Math.nextDown(NaN) = NaN
Math.nextDown(4.9E-324) = 0.0
Math.nextDown(-Infinity) = -Infinity




package com.logicbig.example.math;

public class NextDownExample2 {

public static void main(String... args) {
findNextDown(11.7f);
findNextDown(768.129f);
findNextDown(-23f);
findNextDown(0.0f);
findNextDown(0.0f / 0);
findNextDown(Float.MIN_VALUE);
findNextDown(Float.NEGATIVE_INFINITY);
}

private static void findNextDown(float f) {
float nextDown = Math.nextDown(f);
System.out.printf("Math.nextDown(%s) = %s%n", f, nextDown);
}
}

Output

Math.nextDown(11.7) = 11.699999
Math.nextDown(768.129) = 768.12897
Math.nextDown(-23.0) = -23.000002
Math.nextDown(0.0) = -1.4E-45
Math.nextDown(NaN) = NaN
Math.nextDown(1.4E-45) = 0.0
Math.nextDown(-Infinity) = -Infinity




See Also