Always false float comparisons

Marco Leise via Digitalmars-d digitalmars-d at puremagic.com
Mon May 9 13:32:40 PDT 2016


Am Mon, 09 May 2016 15:56:21 +0000
schrieb Nordlöw <per.nordlow at gmail.com>:

> On Monday, 9 May 2016 at 12:28:04 UTC, Walter Bright wrote:
> > On 5/9/2016 4:38 AM, Nordlöw wrote:  
> >> Would that include comparison of variables only aswell?  
> > No.  
> 
> Why?

Because the float would be converted to double without loss of
precision just like uint == ulong is a valid comparison which
can yield 'true' in 2^32 cases.
float == 1.30 on the other hand is false in any case.
You'd have to warn on _every_ comparison with a widening
conversion to be consistent!

-- 
Marco



More information about the Digitalmars-d mailing list