[GHC] #7858: Fix definitions of abs/signum for Floats/Doubles
GHC
ghc-devs at haskell.org
Mon Apr 21 11:52:02 UTC 2014
#7858: Fix definitions of abs/signum for Floats/Doubles
-------------------------------------+------------------------------------
Reporter: lerkok | Owner:
Type: bug | Status: patch
Priority: normal | Milestone:
Component: libraries/base | Version: 7.6.3
Resolution: | Keywords: floating point
Operating System: Unknown/Multiple | Architecture: Unknown/Multiple
Type of failure: None/Unknown | Difficulty: Unknown
Test Case: | Blocked By:
Blocking: | Related Tickets:
-------------------------------------+------------------------------------
Changes (by bernalex):
* cc: ekmett (added)
* status: new => patch
Comment:
I added my patches for this here per SPJ's suggestion.
The signum patch does not work. I do not know why. It must be due to GHC
internals, because the function itself is fine as may be verified by
copying
{{{
signumFix x
| x == 0.0 = x
| isNaN x = x
| x > 0.0 = 1
| otherwise = negate 1
}}}
into a file signumfix.hs and :l signumfix.hs into GHCi. signumFix (-0.0 ::
Float) will now return -0.0, where Prelude.signum returns 0.0 with the
same argument.
Here is a core dump of me invoking my Prelude.signum after building
GHC/GHCi with my patches:
{{{
Prelude> abs (-0.0 :: Float)
==================== Simplified expression ====================
let {
it_aqt :: GHC.Types.Float
[LclId,
Str=DmdType,
Unf=Unf{Src=<vanilla>, TopLvl=False, Arity=0, Value=False,
ConLike=False, WorkFree=False, Expandable=False,
Guidance=IF_ARGS [] 70 0}]
it_aqt =
GHC.Num.abs
@ GHC.Types.Float
GHC.Float.$fNumFloat
(GHC.Num.negate
@ GHC.Types.Float
GHC.Float.$fNumFloat
(GHC.Types.F# (__float 0.0))) } in
GHC.Base.thenIO
@ ()
@ [()]
(System.IO.print @ GHC.Types.Float GHC.Float.$fShowFloat it_aqt)
(GHC.Base.returnIO
@ [()]
(GHC.Types.:
@ ()
(it_aqt
`cast` (UnivCo representational GHC.Types.Float ()
:: GHC.Types.Float ~# ()))
(GHC.Types.[] @ ())))
0.0
Prelude> signum (-0.0 :: Float)
==================== Simplified expression ====================
let {
it_aKQ :: GHC.Types.Float
[LclId,
Str=DmdType,
Unf=Unf{Src=<vanilla>, TopLvl=False, Arity=0, Value=False,
ConLike=False, WorkFree=False, Expandable=False,
Guidance=IF_ARGS [] 70 0}]
it_aKQ =
GHC.Num.signum
@ GHC.Types.Float
GHC.Float.$fNumFloat
(GHC.Num.negate
@ GHC.Types.Float
GHC.Float.$fNumFloat
(GHC.Types.F# (__float 0.0))) } in
GHC.Base.thenIO
@ ()
@ [()]
(System.IO.print @ GHC.Types.Float GHC.Float.$fShowFloat it_aKQ)
(GHC.Base.returnIO
@ [()]
(GHC.Types.:
@ ()
(it_aKQ
`cast` (UnivCo representational GHC.Types.Float ()
:: GHC.Types.Float ~# ()))
(GHC.Types.[] @ ())))
0.0
}}}
Please note that the abs patch works well and is likely ready to go.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/7858#comment:3>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list