Always false float comparisons

ZombineDev via Digitalmars-d digitalmars-d at puremagic.com
Mon May 9 04:16:53 PDT 2016


On Monday, 9 May 2016 at 09:10:19 UTC, Walter Bright wrote:
> Don Clugston pointed out in his DConf 2016 talk that:
>
>     float f = 1.30;
>     assert(f == 1.30);
>
> will always be false since 1.30 is not representable as a 
> float. However,
>
>     float f = 1.30;
>     assert(f == cast(float)1.30);
>
> will be true.
>
> So, should the compiler emit a warning for the former case?

Yes, I think it is a good idea, just like emitting a warning for 
mismatched signed/unsigned comparison.


More information about the Digitalmars-d mailing list