Wouldn't max( x,-x ) cover everything ? Wouldn't max( x,-x ) cover everything ? return a >= b ? a : b;
But if x is -0.0, you're back to the same problem that -0.0 >= +0.0 actually turns out to be true and not false, hence the return value will be -0.0.Looking at the actual implementation[0], doubleToRawLongBits is used again here to take care of this edge case. So it would work, but a lot slower than the version given in the article.
0: https://github.com/openjdk/jdk/blob/36e2ddad4d2ef3ce27475af6...
(changing greater equal to just greater). Would the problem then still persist?
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.
Try it and you'll see.