[Issue 13489] Boolean semantics of floating point types should use "<> 0"
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Wed Sep 24 23:07:34 PDT 2014
https://issues.dlang.org/show_bug.cgi?id=13489
Ketmar Dark <ketmar at ketmar.no-ip.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |ketmar at ketmar.no-ip.org
--- Comment #3 from Ketmar Dark <ketmar at ketmar.no-ip.org> ---
(In reply to Walter Bright from comment #2)
> Having cast(bool)d yield different results than d!=0 to me is very
> surprising behavior.
for me too. NaN is clearly not 0, so it's 'true'.
but maybe compiler should produce warning telling programmer that he is about
to summon a dragon? i.e. for implicit converts to boolean, like `if (d)` and
`assert(d)` compiler will tell that "implicit convertsion of double to boolean
leads to undesired results, please use explicit cast(bool)".
as for '!=' vs '<>'... i don't know. it's easy to emit a warning, but i can't
think out sane method to hush the compiler if "!=" is what i really want.
--
More information about the Digitalmars-d-bugs
mailing list