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. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. Object obj = Float.MIN_VALUE; //1.40129846432481707E-45;
  13. float floatVal = ((Number) obj).floatValue();
  14. double doubleVal = ((Number) obj).doubleValue();
  15.  
  16. System.out.println("obj is a " + obj.getClass().getSimpleName());
  17. boolean result = floatVal == Float.MIN_VALUE;
  18. System.out.printf("%.60f == %.60f: %s.\n" , floatVal, Float.MIN_VALUE, result );
  19.  
  20. result = doubleVal == Float.MIN_VALUE;
  21. System.out.printf("%.60f == %.60f: %s.\n" , doubleVal, Float.MIN_VALUE, result );
  22.  
  23.  
  24.  
  25. obj = 1.40129846432481707E-45;
  26.  
  27. floatVal = ((Number) obj).floatValue();
  28. doubleVal = ((Number) obj).doubleValue();
  29. Formatter fmt = new Formatter();
  30.  
  31. System.out.println("obj is a " + obj.getClass().getSimpleName());
  32. result = floatVal == Float.MIN_VALUE;
  33. System.out.println(fmt.format("%18.17e", floatVal) + " == " + fmt.format("%18.17e", Float.MIN_VALUE) + "? " + result );
  34. result = doubleVal == Float.MIN_VALUE;
  35. System.out.println(fmt.format("%18.17e", doubleVal) + "= = " + fmt.format("%18.17e",Float.MIN_VALUE) + "? " + result );
  36. }
  37. }
Success #stdin #stdout 0.11s 28208KB
stdin
Standard input is empty
stdout
obj is a Float
0.000000000000000000000000000000000000000000001401298464324817 == 0.000000000000000000000000000000000000000000001401298464324817: true.
0.000000000000000000000000000000000000000000001401298464324817 == 0.000000000000000000000000000000000000000000001401298464324817: true.
obj is a Double
1.40129846432481700e-45 == 1.40129846432481700e-451.40129846432481700e-45? true
1.40129846432481700e-451.40129846432481700e-451.40129846432481700e-45= = 1.40129846432481700e-451.40129846432481700e-451.40129846432481700e-451.40129846432481700e-45? true