fork download
  1. class Ideone
  2. {
  3. public static void main (String[] args)
  4. {
  5. System.out.println("Moving by an eight in single precision");
  6. runIt(2097151.f, 0.1, 10);
  7. runIt(2097151., 0.1, 10);
  8.  
  9. System.out.println("Moving by a fourth in single precision");
  10. runIt(2097152.f, 0.1, 10);
  11. runIt(2097152., 0.1, 10);
  12.  
  13. System.out.println("Moving by a half in single precision");
  14. runIt(4194304.f, 0.1, 10);
  15. runIt(4194304., 0.1, 10);
  16. }
  17.  
  18. public static void runIt(float start, double delta, int steps)
  19. {
  20. System.out.println("Single precision");
  21.  
  22. double value = start;
  23. for(int i = 0; i < steps; ++i)
  24. {
  25. System.out.println(String.format("%.8f", (float)value));
  26. value += delta;
  27. }
  28.  
  29. System.out.println();
  30. }
  31.  
  32. public static void runIt(double start, double delta, int steps)
  33. {
  34. System.out.println("Double precision");
  35.  
  36. double value = start;
  37. for(int i = 0; i < steps; ++i)
  38. {
  39. System.out.println(String.format("%.8f", value));
  40. value += delta;
  41. }
  42.  
  43. System.out.println();
  44. }
  45. }
Success #stdin #stdout 0.11s 320256KB
stdin
Standard input is empty
stdout
Moving by an eight in single precision
Single precision
2097151.00000000
2097151.12500000
2097151.25000000
2097151.25000000
2097151.37500000
2097151.50000000
2097151.62500000
2097151.75000000
2097151.75000000
2097151.87500000

Double precision
2097151.00000000
2097151.10000000
2097151.20000000
2097151.30000000
2097151.40000000
2097151.50000000
2097151.60000000
2097151.70000000
2097151.80000000
2097151.90000000

Moving by a fourth in single precision
Single precision
2097152.00000000
2097152.00000000
2097152.25000000
2097152.25000000
2097152.50000000
2097152.50000000
2097152.50000000
2097152.75000000
2097152.75000000
2097153.00000000

Double precision
2097152.00000000
2097152.10000000
2097152.20000000
2097152.30000000
2097152.40000000
2097152.50000000
2097152.60000000
2097152.70000000
2097152.80000000
2097152.90000000

Moving by a half in single precision
Single precision
4194304.00000000
4194304.00000000
4194304.00000000
4194304.50000000
4194304.50000000
4194304.50000000
4194304.50000000
4194304.50000000
4194305.00000000
4194305.00000000

Double precision
4194304.00000000
4194304.10000000
4194304.20000000
4194304.30000000
4194304.40000000
4194304.50000000
4194304.60000000
4194304.70000000
4194304.80000000
4194304.90000000