Suppose x
is a floating point number, I want to know whether - ( - x)
equals to x
in general?
Let us ignore corner cases such as x = max_floating_point_number / min_floating_number.
In general, yes; negation of a floating-point value induces no error or loss of precision. (It just involves flipping a bit.)
The one exception to this is NaN. -(-(NaN)) is NaN, but NaN does not compare equal to any value, even another NaN. That's firmly in the realm of "corner cases", though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With