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

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



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

abs (-0.0::Float) and abs (-0.0::Double) previously returned -0.0, when
they should return 0.0. This patch fixes this.
Signed-off-by: bernalex's avatarAlexander Berntsen <alexander@plaimi.net>

Test Plan: abs (-0.0::Double) should = 0.0 instead of (-0.0)

Reviewers: ekmett, hvr, austin, rwbarton

Reviewed By: austin, rwbarton

Subscribers: phaskell, trofi, simonmar, relrod, ezyang, carter

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

GHC Trac Issues: #7858
parent 88b1f99d
......@@ -205,8 +205,9 @@ instance Num Float where
(-) x y = minusFloat x y
negate x = negateFloat x
(*) x y = timesFloat x y
abs x | x >= 0.0 = x
| otherwise = negateFloat x
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
......@@ -370,8 +371,9 @@ instance Num Double where
(-) x y = minusDouble x y
negate x = negateDouble x
(*) x y = timesDouble x y
abs x | x >= 0.0 = x
| otherwise = negateDouble x
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
......
......@@ -18,6 +18,8 @@
enabled, so that the `Monoid` instance for `Proxy` are polykinded
like `Proxy` itself is.
* Make `abs` handle (-0.0) correctly per IEEE-754.
## 4.7.0.1 *Jul 2014*
* Bundled with GHC 7.8.3
......
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