Always false float comparisons
Xinok via Digitalmars-d
digitalmars-d at puremagic.com
Mon May 9 12:15:20 PDT 2016
On Monday, 9 May 2016 at 18:51:58 UTC, tsbockman wrote:
> On Monday, 9 May 2016 at 18:37:10 UTC, Xinok wrote:
>> ...
>> (3) Generalize it to all comparisons as well, including < and
>> ...
> (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.)
> ...
Not necessarily. Reusing 1.3 from the original case, the
following assertion passes:
float f = 1.3;
assert(f < 1.3);
And considering we also have <= and >=, we may as well check all
of the comparison operators. It's a complex issue because there
isn't necessarily right or wrong behavior, only things that
*might* be wrong. But if we want to truly detect all possible
cases of incorrect behavior, then we have to be exhaustive in our
checks.
More information about the Digitalmars-d
mailing list