#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 altaic):
I would have sworn I tested this earlier since I noticed `showSignedFloat`
appears to be unnecessary (`showFloat` calls `formatRealFloat` which
handles signed `RealFloat`, although it doesn't call `showParen` which is
necessary for `showsPrec`).
So, I changed the `showChar '-'` to `showChar 'n'` in `showSignedFloat`
with the following results:
{{{
Prelude GHC.Float> showSignedFloat showFloat 0 (-1.0 :: Double) ""
"n1.0"
Prelude GHC.Float> showsPrec 0 (-1.0 :: Double) ""
"n-1.0"
}}}
Clearly it's not negating properly when `showSignedFloat` calls `showPos
(-x))`, and the extra '-' is coming from `formatRealFloat`. Is the sign
stored in a separate register that's getting clobbered? In
`StgPrimFloat.c` it appears to be so; I scattered `ASSERT`s around to no
avail.
Of course the easy fix would be to clean up the negative checks so only
one '-' is possible, however there's definitely a deeper problem. And I
still don't understand why calling `showSignedFloat showFloat` directly is
at all different from calling `showsPrec`.
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/4867#comment:35>
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