IEEE-754 abs and sign

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


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
Prelude> signum (-0.0) :: Float

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

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

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