literals

Walter Bright newshound1 at digitalmars.com
Sun Mar 28 15:04:52 PDT 2010


Don wrote:
> (1) Converting a floating point literal into a double literal is usually 
> not lossless.
> 0.5f, 0.5, and 0.5L are all exactly the same number, since they are 
> exactly representable.
> But 0.1 is not the same as 0.1L.

It depends. The D compiler internally stores all floating point constants, 
regardless of type, in full 80 bit precision. Constant folding and CTFE are all 
carried out in 80 bit precision regardless of type. The only time it is actually 
truncated to the shorter formats is when writing it out to the object file.

The central idea is that more precision == better. If your floating point 
algorithm breaks if precision increases, then the algorithm is a bad one.

The only time I've seen code that relied on roundoff errors is in test suites 
that specifically tested for it.



More information about the Digitalmars-d mailing list