Strange double to uint conversion

Luiz Silveira zertyz at gmail.com
Tue Nov 19 12:28:01 UTC 2019


On Monday, 18 November 2019 at 21:54:53 UTC, Steven Schveighoffer 
wrote:
> You are expecting floating point to behave as if it is stored 
> as a decimal number. It's not.

I was actually asking why 'c' and 'c2' functions behave 
differently. After mipri's answer I learned that the default 
floating point representation for literals in D is 'real', not 
'double', as in C++.

Changing the type to real resolves the different behavior I was 
observing.

Just out of curiosity: in C++ a similar code also issues 3704 -- 
but the same value is returned by 'c' and 'c2', hence my doubt. 
Using, in C++, 'long double' and suffixing all floating point 
literals with 'l' gave me the same results as my "fixed" D code.

But, yes, thanks for clarifying about math.round.


More information about the Digitalmars-d-learn mailing list