3 ms·
Couldn't you also implement max as return a>b? a:b; (changing greater equal to just greater). Would the problem then still persist?
by andi999 5y ago
Couldn't you also implement max as return a>b? a:b;
(changing greater equal to just greater). Would the problem then still persist?
- kmm 5y agoPositive and negative zero cannot be distinguished by normal equality checks, meaning +0.0 == -0.0. Therefore, for consistency's sake +0.0 > -0.0 ought to be false, which would yield a return value of -0.0 for max(+0.0, -(+0.0))
- gvx 5y agoThat wouldn't solve it: max(0.0, -0.0) would be false ? 0.0 : -0.0 The problem is that 0.0 == -0.0. As long as you don't take care of signed zero, you cannot guarantee that abs(x) has no negative sign.