Always false float comparisons
tsbockman via Digitalmars-d
digitalmars-d at puremagic.com
Mon May 9 11:51:58 PDT 2016
On Monday, 9 May 2016 at 18:37:10 UTC, Xinok wrote:
> (1) Yes, emit a warning for this case.
> (2) Generalize it to all variables, like Nordlöw suggested.
> (3) Generalize it to all comparisons as well, including < and >
> .
> (4) While we're at it, let's also emit a warning when comparing
> signed and unsigned types.
> (5) Dare I say it... warn against implicit conversions of
> double to float.
> (6) The same applies to "real" as well.
>
> All of these scenarios are capable of producing "incorrect"
> results, are a source of discrete bugs (often corner cases that
> we failed to consider and test), and can be hard to detect.
> It's about time we stopped being stubborn and flagged these
> things as warnings. Even if they require a special compiler
> flag and are disabled by default, that's better than nothing.
(1) is good, because the code in question is always wrong.
(2) is a logical extension, in those cases where constant folding
and VRP can prove that the code is always wrong.
(3) Makes no sense though; inequalities with mixed floating-point
types are perfectly safe. (Well, as safe as any floating-point
code can be, anyway.)
(4) is already planned; it's just taking *a lot* longer than
anticipated to actually implement it:
https://issues.dlang.org/show_bug.cgi?id=259
https://github.com/dlang/dmd/pull/1913
https://github.com/dlang/dmd/pull/5229
More information about the Digitalmars-d
mailing list