Printing shortest decimal form of floating point number with Mir

Walter Bright newshound2 at digitalmars.com
Tue Jan 5 09:47:41 UTC 2021


On 1/4/2021 11:22 PM, 9il wrote:
> I can't reproduce the same DMD output as you.

I did it on Windows 32 bit. I tried it on Linux 32, which does indeed show the 
behavior you mentioned. At the moment I don't know why the different behaviors.

https://issues.dlang.org/show_bug.cgi?id=21526


> It just uses SSE, which I think a good way to go, haha.

As I mentioned upthread, it will use SSE when SSE is baseline on the CPU target, 
and it will always round to precision.


> The only D compiler that uses excess precision is DMD and only if -O flag is 
> passed. The same example compiled with GDC uses write-read codes. LDC uses SSE 
> codes.

DMD still supports baseline 32 bit Windows that does not have XMM registers.


> As for C, it allows an intuitive built-in way to work with exact precision when 
> an assignment works like a directive to use exact precision for the expression 
> result, unlike D. It doesn't cover all cases but an intuitive and very easy way 
> to do things the right way.

It's a rarity of cases that require the rounding, and DMD does have the 
functions in druntime to do it for those cases. It's what people doing numerics 
have asked for. It means the write/read penalty is only there when it is 
actually required.

In any case, this is an issue for the past. The future is XMM code, and DMD does 
the round-to-precision in all XMM code generation. If you find a case where it 
isn't, please file a bugzilla and let me know so I can fix it.



More information about the Digitalmars-d-announce mailing list