On Thursday, 11 January 2018 at 21:24:30 UTC, kdevel wrote:
On Thursday, 11 January 2018 at 20:44:13 UTC, kdevel wrote:
On Thursday, 11 January 2018 at 20:35:03 UTC, kdevel wrote:
<--- loop output missing
loop.d
```
import std.stdio;
import decimal;
void loopme(T) ()
{
"---".writeln;
T e = T(1000);
while (e > T(1e-6)) {
e.writeln;
e /= 10;
}
}
void main ()
{
loopme!float;
loopme!decimal32;
}
```
This prints
---
1000
100
10
1
0.1
0.01
0.001
0.0001
1e-05
---
1000
100
10
1
0.1
0.0100000 <--
0.00100000 <--
0.000100000 <--
1.00000e-05 <--
Why are there trailing zeroes?
As I said, the %g specifier (used by default in writeln) makes me
cry. Anyway, I made some modifications, now it prints correctly
(in fact using floats just proves the need of decimals on my
system):
--
1000
100
10
1
0.1
0.01
0.00099999
0.000099999
1e-05
---
1000
100
10
1
0.1
0.01
0.001
0.0001
1e-05
Regarding printf, I cannot help, this is a C function, has
nothing to do with D formatting.