I know that signed zeros are used to distinguish underflow from positive or negative numbers, and so it’s worth distinguishing them. Intuitively I feel that the absolute value of -0.0 should be 0.0. However, this is not what Haskell says:
Prelude> abs (-0.0)
-0.0
For what it’s worth, Python 2.7 disagrees:
>>> -0.0
-0.0
>>> abs(-0.0)
0.0
Is this a bug, or a part of the standard?
The behaviour you describe is definitely inconsistent with the IEEE 754 standard, which in its most recent incarnation says:
That’s in section 5.5.1 of IEEE 754-2008, entitled ‘Sign bit operations’. Though I can’t give a link to the standard itself, you can see roughly the same language in the last available public draft of the standard, in section 7.5.1. (In general the standard differs quite significantly from that draft, but this bit’s almost unchanged.)
That doesn’t make it a bug in Haskell unless Haskell specifically claims to follow the IEEE 754 standard, and moreover claims that the implementation of
absin the Prelude should map to the IEEE 754absfunction. The standard merely requires that theabsoperation must be provided, but says nothing about how it might be spelled.