Commit d9a20573 authored by bernalex's avatar bernalex Committed by Austin Seipp
Browse files

Make Prelude.signum handle -0.0 correctly (#7858)



Summary:
Make the `Float` and `Double` implementations of `signum` handle -0.0
correctly per IEEE-754.

This, together with "Make Prelude.abs handle -0.0 correctly (#7858)",
fixes Trac #7858.

Depends on D145
Signed-off-by: bernalex's avatarAlexander Berntsen <alexander@plaimi.net>

Test Plan:
signum of (-0.0) should be (-0.0) not 0.0.

Test program:

  main =
    putStrLn $ p ++ " " ++ n
    where
      f = show . signum
      p = f (-0.0 :: Double)
    n = f (0.0 :: Double)

Reviewers: ekmett, hvr, rwbarton, austin

Reviewed By: austin

Subscribers: phaskell, simonmar, relrod, ezyang, carter

Differential Revision: https://phabricator.haskell.org/D148

GHC Trac Issues: #7858
parent 6f6ee6ea
......@@ -208,9 +208,9 @@ instance Num Float where
abs x | x == 0 = 0 -- handles (-0.0)
| x > 0 = x
| otherwise = negateFloat x
signum x | x == 0.0 = 0
| x > 0.0 = 1
| otherwise = negate 1
signum x | x > 0 = 1
| x < 0 = negateFloat 1
| otherwise = x -- handles 0.0, (-0.0), and NaN
{-# INLINE fromInteger #-}
fromInteger i = F# (floatFromInteger i)
......@@ -374,9 +374,10 @@ instance Num Double where
abs x | x == 0 = 0 -- handles (-0.0)
| x > 0 = x
| otherwise = negateDouble x
signum x | x == 0.0 = 0
| x > 0.0 = 1
| otherwise = negate 1
signum x | x > 0 = 1
| x < 0 = negateDouble 1
| otherwise = x -- handles 0.0, (-0.0), and NaN
{-# INLINE fromInteger #-}
fromInteger i = D# (doubleFromInteger i)
......
......@@ -18,7 +18,7 @@
enabled, so that the `Monoid` instance for `Proxy` are polykinded
like `Proxy` itself is.
* Make `abs` handle (-0.0) correctly per IEEE-754.
* Make `abs` and `signum` handle (-0.0) correctly per IEEE-754.
## 4.7.0.1 *Jul 2014*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment