#4867: ghci displays negative floats incorrectly (was: Incorrect result from 
trig
functions)
-------------------------------+--------------------------------------------
    Reporter:  gwright         |        Owner:  gwright                    
        Type:  bug             |       Status:  new                        
    Priority:  high            |    Milestone:  7.0.2                      
   Component:  GHCi            |      Version:  7.0.1                      
    Keywords:                  |     Testcase:                             
   Blockedby:                  |   Difficulty:                             
          Os:  MacOS X         |     Blocking:                             
Architecture:  x86_64 (amd64)  |      Failure:  Incorrect result at runtime
-------------------------------+--------------------------------------------

Comment(by gwright):

 The source of this trouble seems to be in `formatRealFloat` in
 `libraries/Base/GHC/Float.lhs`.

 Here's the top of that function:
 {{{
 formatRealFloat :: (RealFloat a) => FFFormat -> Maybe Int -> a -> String
 formatRealFloat fmt decs x
    | isNaN x                   = "NaN"
    | isInfinite x              = if x < 0 then "-Infinity" else "Infinity"
    | x < 0 || isNegativeZero x = '-' : doFmt fmt (floatToDigits (toInteger
 base) (-x))
    | otherwise                 = doFmt fmt (floatToDigits (toInteger base)
 x)
  where
   base = 10
   ...
 }}}

 The clue is that the incorrectly displayed numbers always have the correct
 sign.  The guard `| x < 0 || isNegativeZero` is satisfied, so the minus
 sign is prefixed to the formatted digits.  In retrospect, if I had paid
 more attention to the gdb traces I did earlier, I would have seen this.

 Still don't know exactly what goes wrong yet.

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

_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to