[GHC] #8780: abs for IEEE floating point is slightly wrong.

#8780: abs for IEEE floating point is slightly wrong. ------------------------------------+------------------------------------- Reporter: augustss | Owner: Type: bug | Status: new Priority: low | Milestone: Component: Compiler | Version: 7.6.3 Keywords: | Operating System: Unknown/Multiple Architecture: Unknown/Multiple | Type of failure: None/Unknown Difficulty: Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | ------------------------------------+------------------------------------- Evaluating abs(-0) gives the answer -0. This unexpected since it breaks invariants like 1/(abs x) >= 0. So abs(-0) should be 0. This is also the norm for other languages. Together with this change, signum should also be changed so signum(-0) is -0. This maintains the invariant abs x * signum x == x. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8780 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8780: abs for IEEE floating point is slightly wrong. -------------------------------------+------------------------------------- Reporter: augustss | Owner: Type: bug | Status: infoneeded Priority: low | Milestone: Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: | Architecture: Unknown/Multiple Unknown/Multiple | Difficulty: Unknown Type of failure: Incorrect | Blocked By: result at runtime | Related Tickets: Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Changes (by thomie): * status: new => infoneeded * failure: None/Unknown => Incorrect result at runtime Comment: I cannot reproduce your findings. Can you try again, specifying your GHC version, OS and architecture. Thanks. {{{ $ uname -op x86_64 GNU/Linux $ ghc-7.6.3 --interactive GHCi, version 7.6.3: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linking ... done. Prelude> abs(-0) 0 Prelude> signum(-0) == 0 True Prelude> let x = -0 in abs x * signum x == x True }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8780#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8780: abs for IEEE floating point is slightly wrong. -------------------------------------+------------------------------------- Reporter: augustss | Owner: Type: bug | Status: infoneeded Priority: low | Milestone: Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by augustss): It seems the printing of -0 has changed. Here's my session {{{ $ ghci GHCi, version 7.8.3: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linking ... done. Prelude> let x = -0 Prelude> x 0 Prelude> isNegativeZero x True Prelude> isNegativeZero (abs x) True Prelude> isNegativeZero (signum x) False }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8780#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8780: abs for IEEE floating point is slightly wrong. -------------------------------------+------------------------------------- Reporter: augustss | Owner: Type: bug | Status: closed Priority: low | Milestone: Component: Compiler | Version: 7.6.3 Resolution: duplicate | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: #7858 | Differential Revisions: -------------------------------------+------------------------------------- Changes (by thomie): * status: infoneeded => closed * resolution: => duplicate * related: => #7858 Comment: A fix for both issues will be in 7.10, see #7858. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8780#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8780: abs for IEEE floating point is slightly wrong. -------------------------------------+------------------------------------- Reporter: augustss | Owner: Type: bug | Status: closed Priority: low | Milestone: Component: Compiler | Version: 7.6.3 Resolution: duplicate | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: #7858 | Differential Revisions: -------------------------------------+------------------------------------- Comment (by rwbarton): Replying to [comment:2 augustss]:
It seems the printing of -0 has changed. Here's my session
{{{ $ ghci GHCi, version 7.8.3: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linking ... done. Prelude> let x = -0 Prelude> x 0 }}}
This part is just because `x` defaulted to Integer on this line; `-0.0` is still printed as `-0.0`. (7.8.3 has the MR disabled in ghci by default.) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8780#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC