Always false float comparisons

Iain Buclaw via Digitalmars-d digitalmars-d at puremagic.com
Mon May 16 00:54:32 PDT 2016


On 16 May 2016 at 09:22, Ola Fosheim Grøstad via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
> On Monday, 16 May 2016 at 06:34:04 UTC, Iain Buclaw wrote:
>>
>> This says more about promoting float operations to double than anything
>> else, and has nothing to do with CTFE.
>
>
> No, promoting to double is ok.

Your own example:

const float value = 1.30;
float  copy = value;
assert(value*0.5 ==  copy*0.5);

Versus how you'd expect it to work.

const float value = 1.30;
float  copy = value;
assert(cast(float)(value*0.5) ==  cast(float)(copy*0.5)); // Compare
as float, not double.



More information about the Digitalmars-d mailing list