So I modified the code a little to add in a NumberFormat
(and reduce the number of loops)
double waittime = 100;
int index = 0;
NumberFormat nf = NumberFormat.getNumberInstance();
nf.setMinimumFractionDigits(1000);
while (true) {
index++;
System.out.println(String.valueOf(index) + "\t" + (waittime / 1000) + "; " + nf.format(waittime) + " seconds");
waittime = waittime / 2;
if (waittime <= 0) {
break;
}
try {
Thread.sleep((long) waittime);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
Which outputs...
.
.
.
1072 4.9E-324; 0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000039530000000000000000 seconds
1073 0.0; 0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000019760000000000000000 seconds
1074 0.0; 0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009900000000000000000 seconds
1075 0.0; 0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004940000000000000000 seconds
1076 0.0; 0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002470000000000000000 seconds
1077 0.0; 0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001240000000000000000 seconds
1078 0.0; 0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000590000000000000000 seconds
1079 0.0; 0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000 seconds
1080 0.0; 0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000150000000000000000 seconds
1081 0.0; 0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000 seconds
1082 0.0; 0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000049000000000000000 seconds
So, as you can see (waittime / 1000)
eventually prints 0.0
, but the actual value (at least to 1000 decimal digits) isn't zero.
So it's just an artifact of how Java is representing the raw value
aengus comments is a good indication of why the loop will eventually break though
Alternate: Just show waittime
without dividing by 1000, which is causing underflow early in the display:
1078 4.9E-324 seconds, (6.176E-321 ms)
1079 4.9E-324 seconds, (3.09E-321 ms)
1080 0.0 seconds, (1.54E-321 ms)
1081 0.0 seconds, (7.7E-322 ms)
1082 0.0 seconds, (3.85E-322 ms)
1083 0.0 seconds, (1.93E-322 ms)
1084 0.0 seconds, (1.0E-322 ms)
1085 0.0 seconds, (4.9E-323 ms)
1086 0.0 seconds, (2.5E-323 ms)
1087 0.0 seconds, (1.0E-323 ms)
1088 0.0 seconds, (4.9E-324 ms)