Always false float comparisons

Timon Gehr via Digitalmars-d digitalmars-d at puremagic.com
Fri May 13 12:48:45 PDT 2016


On 13.05.2016 21:25, Walter Bright wrote:
> 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.
>

IMO the compiler should never be allowed to use a precision different 
from the one specified.


More information about the Digitalmars-d mailing list