IEEE-754 abs and sign

Christian Maeder Christian.Maeder at dfki.de
Thu Jan 20 10:45:38 CET 2011


Hi,

should the following hold?

   abs (-0.0) = 0.0

   sign (-0.0) = -0.0

The generic definitions for abs and signum in ghc produce:

Prelude> abs (-0.0) :: Float
-0.0
Prelude> signum (-0.0) :: Float
0.0

The outcome for "abs (-0.0)" looks irritating.
I know it does not matter for comparisons and the documented properties
hold:

<cite>
The functions abs and signum should satisfy the law:

 abs x * signum x == x

For real numbers, the signum is either -1 (negative), 0 (zero) or 1
(positive).
</cite>

Yet, I think, for numbers with a negative zero (class RealFloat)
the top two equations above should hold.

Cheers Christian



More information about the Libraries mailing list