[GHC] #7858: Fix definitions of abs/signum for Floats/Doubles

GHC cvs-ghc at haskell.org
Tue Apr 23 05:38:29 CEST 2013


#7858: Fix definitions of abs/signum for Floats/Doubles
-----------------------------+----------------------------------------------
Reporter:  lerkok            |          Owner:                  
    Type:  bug               |         Status:  new             
Priority:  normal            |      Component:  libraries/base  
 Version:  7.6.3             |       Keywords:  floating point  
      Os:  Unknown/Multiple  |   Architecture:  Unknown/Multiple
 Failure:  None/Unknown      |      Blockedby:                  
Blocking:                    |        Related:                  
-----------------------------+----------------------------------------------
 The current definition of abs doesn't work correctly for -0.0 (negative
 zero); and the signum function doesn't return NaN on NaN. The issue is
 discussed in detail in the following thread:

    http://www.haskell.org/pipermail/libraries/2013-April/019677.html

 To summarize, the proposal is to change both the Float and Double instance
 definitions for signum/abs as follows:

 {{{
     signum x
          | x == 0    = x
          | isNaN x   = x
          | x > 0     = 1
          | otherwise = negate 1
     abs x
          | isNegativeZero x = 0
          | x >= 0           = x
          | otherwise        = negate x
 }}}

 Simon PJ expressed interest in taking advantage of the underlying
 platforms floating-point instructions when available to speed things up,
 and the above referenced thread has some discussion regarding how this
 might be done. However, it might be best to start with a "correct"
 implementation first, and then later worry about speed.

 On a related note, this "bug" is actually present in the Haskell'98
 standard definition itself, which seems to have overlooked NaN's and
 negative-0's. It'd be great if the standard got a similar amendment as
 well.

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/7858>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler



More information about the ghc-tickets mailing list