#3676: realToFrac doesn't sanely convert between floating types
----------------------------------+-----------------------------------------
Reporter: draconx | Owner: simonmar
Type: bug | Status: assigned
Priority: normal | Milestone: 6.12.2
Component: libraries (other) | Version: 6.12.1
Keywords: | Difficulty:
Os: Unknown/Multiple | Testcase:
Architecture: x86_64 (amd64) | Failure: None/Unknown
----------------------------------+-----------------------------------------
Comment(by simonmar):
I've fixed this, but I'm not sure the fix is an improvement.
{{{
Thu Feb 11 02:19:55 PST 2010 Simon Marlow <[email protected]>
* Handle NaN, -Infinity and Infinity in the toRational for Float/Double
(#3676)
M ./GHC/Float.lhs -2 +9
M ./GHC/Real.lhs -1 +2
}}}
and in ghc:
{{{
Thu Feb 11 05:15:43 PST 2010 Simon Marlow <[email protected]>
* don't constant fold division that would result in negative zero
(#3676)
}}}
It has some slightly odd consequences. Someone ought to take a broader
look at this in the context of refining the Haskell standard. e.g.
{{{
Prelude> toRational (-0 :: Double) == - toRational (0 :: Double)
False
}}}
whereas previously this was True.
The underlying problem is that the Rational type doesn't really include
these strange values; it has been hacked in a few places so that certain
unnormalised Rational values are used to represent strange floating point
values, e.g. `0 :% 0` represents `NaN` and `fromRational` knows about it,
but there's no official way to generate one of these (`0/0 :: Rational`
gives an exception), they are only used "internally" by the libraries to
make `read "NaN" :: Double` work.
The change I made is to make `toRational (0/0 :: Double)` generate `0 :%
0`, and similarly for the other strange values, but these had odd
consequences, because these special `Rational` values are not normalised.
However, this does fix a real bug (the subject of this ticket).
What do people think?
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/3676#comment:10>
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