fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. static void check(double x) {
  11. double a, b;
  12. System.out.printf("%9s %9s %23s %5s%n", x, a = x - Math.ulp(x), b = Math.nextAfter(x, Double.NEGATIVE_INFINITY),
  13. a == b);
  14. System.out.printf("%9s %9s %23s %5s%n", x, a = x + Math.ulp(x), b = Math.nextAfter(x, Double.POSITIVE_INFINITY),
  15. a == b);
  16. System.out.println();
  17.  
  18. }
  19. public static void main (String[] args) throws java.lang.Exception
  20. {
  21. check(0);
  22. check(Double.POSITIVE_INFINITY);
  23. check(Double.NEGATIVE_INFINITY);
  24. check(Double.NaN);
  25. }
  26. }
Success #stdin #stdout 0.04s 4386816KB
stdin
Standard input is empty
stdout
      0.0 -4.9E-324               -4.9E-324  true
      0.0  4.9E-324                4.9E-324  true

 Infinity       NaN  1.7976931348623157E308 false
 Infinity  Infinity                Infinity  true

-Infinity -Infinity               -Infinity  true
-Infinity       NaN -1.7976931348623157E308 false

      NaN       NaN                     NaN false
      NaN       NaN                     NaN false