Another take on decimal data types
Dmitry Olshansky
dmitry.olsh at gmail.com
Thu Jan 11 20:40:01 UTC 2018
On Thursday, 11 January 2018 at 20:35:03 UTC, kdevel wrote:
> Great project!
>
> On Monday, 8 January 2018 at 22:16:25 UTC, rumbu wrote:
>> - all format specifiers implemented (%f, %e, %g, %a);
>
> Really?
>
> [...]
>
>> What's next:
>> - more tests;
>
> Here you are:
>
> ```
> import std.stdio;
> import decimal;
>
> void main ()
> {
> decimal32 d = "0.7";
> d *= decimal32("1.05");
> d.writeln;
> printf ("%.2f\n", d);
C’s printf by definition can’t be customized. What did you expect?
>
> float f = 0.7f;
> f *= 1.05f;
> f.writeln;
> printf ("%.2f\n", f);
>
> decimal32 e = 1_000_000_000;
> while (e > 1e-7) {
> e.writeln;
> e /= 10;
> }
> }
> ```
>
> This prints:
>
> 0.735
> 0.00 <--- expected: 0.74
> 0.735
> 0.73
> <--- loop output missing
>
> (DMD64 D Compiler v2.077.1)
More information about the Digitalmars-d-announce
mailing list