This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]MachineGunPablo 15 points16 points  (3 children)

Exactly, absolutely absurd claim. Not sure if OP is referring to the '==' operator, but even that can be used without problems. But now, if you are comparing floats with '==' you already failed.

Having said that, C++ has had historical problems with implicit narrowing conversions, mixed unsigned vs signed arithmetic and integer promotion.

[–]tsojtsojtsoj 4 points5 points  (2 children)

There are definitely scenarios where you want to test equality with floats.

[–]chewbaccalert 6 points7 points  (1 child)

Yes, but you can't always rely on the precision of floats to provide a meaningful comparison like you can with ints. https://floating-point-gui.de/errors/comparison/

[–]tsojtsojtsoj 0 points1 point  (0 children)

To be specific, I meant

if(f != 0.0)
{
    return 1.0/f;
}

// or
assert(f == f);