Always false float comparisons

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Fri May 13 12:25:49 PDT 2016


On 5/12/2016 4:06 PM, Marco Leise wrote:
> Am Mon, 9 May 2016 04:26:55 -0700
> schrieb Walter Bright <newshound2 at digitalmars.com>:
>
>>> I wonder what's the difference between 1.30f and cast(float)1.30.
>>
>> There isn't one.
>
> Oh yes, there is! Don't you love floating-point...
>
> cast(float)1.30 rounds twice, first from a base-10
> representation to a base-2 double value and then again to a
> float. 1.30f directly converts to float.

This is one reason why the compiler carries everything internally to 80 bit 
precision, even if they are typed as some other precision. It avoids the double 
rounding.



More information about the Digitalmars-d mailing list