fork download
  1. class DSDTest {
  2. public static void main(String[] args) {
  3. Double finish = 2.0;
  4. if (args.length > 0) {
  5. try {
  6. finish = Double.parseDouble(args[0]);
  7. } catch (NumberFormatException e) {
  8. System.err.println("Parse " + args[0] + " failed.");
  9. System.exit(-1);
  10. }
  11. }
  12. Double d = finish/2;
  13. Double f = d;
  14. for (int i = 0; i < 54; i++) {
  15. String s = d.toString();
  16. assert Double.parseDouble(s) == d;
  17. System.out.println(
  18. String.format("%s == %a",s, d)
  19. );
  20. if (d == finish) break;
  21. f /= 2; d += f;
  22. }
  23. }
  24. }
  25.  
Success #stdin #stdout 0.12s 320704KB
stdin
Standard input is empty
stdout
1.0 == 0x1.0p0
1.5 == 0x1.8p0
1.75 == 0x1.cp0
1.875 == 0x1.ep0
1.9375 == 0x1.fp0
1.96875 == 0x1.f8p0
1.984375 == 0x1.fcp0
1.9921875 == 0x1.fep0
1.99609375 == 0x1.ffp0
1.998046875 == 0x1.ff8p0
1.9990234375 == 0x1.ffcp0
1.99951171875 == 0x1.ffep0
1.999755859375 == 0x1.fffp0
1.9998779296875 == 0x1.fff8p0
1.99993896484375 == 0x1.fffcp0
1.999969482421875 == 0x1.fffep0
1.9999847412109375 == 0x1.ffffp0
1.9999923706054688 == 0x1.ffff8p0
1.9999961853027344 == 0x1.ffffcp0
1.9999980926513672 == 0x1.ffffep0
1.9999990463256836 == 0x1.fffffp0
1.9999995231628418 == 0x1.fffff8p0
1.999999761581421 == 0x1.fffffcp0
1.9999998807907104 == 0x1.fffffep0
1.9999999403953552 == 0x1.ffffffp0
1.9999999701976776 == 0x1.ffffff8p0
1.9999999850988388 == 0x1.ffffffcp0
1.9999999925494194 == 0x1.ffffffep0
1.9999999962747097 == 0x1.fffffffp0
1.9999999981373549 == 0x1.fffffff8p0
1.9999999990686774 == 0x1.fffffffcp0
1.9999999995343387 == 0x1.fffffffep0
1.9999999997671694 == 0x1.ffffffffp0
1.9999999998835847 == 0x1.ffffffff8p0
1.9999999999417923 == 0x1.ffffffffcp0
1.9999999999708962 == 0x1.ffffffffep0
1.999999999985448 == 0x1.fffffffffp0
1.999999999992724 == 0x1.fffffffff8p0
1.999999999996362 == 0x1.fffffffffcp0
1.999999999998181 == 0x1.fffffffffep0
1.9999999999990905 == 0x1.ffffffffffp0
1.9999999999995453 == 0x1.ffffffffff8p0
1.9999999999997726 == 0x1.ffffffffffcp0
1.9999999999998863 == 0x1.ffffffffffep0
1.9999999999999432 == 0x1.fffffffffffp0
1.9999999999999716 == 0x1.fffffffffff8p0
1.9999999999999858 == 0x1.fffffffffffcp0
1.999999999999993 == 0x1.fffffffffffep0
1.9999999999999964 == 0x1.ffffffffffffp0
1.9999999999999982 == 0x1.ffffffffffff8p0
1.9999999999999991 == 0x1.ffffffffffffcp0
1.9999999999999996 == 0x1.ffffffffffffep0
1.9999999999999998 == 0x1.fffffffffffffp0
2.0 == 0x1.0p1