[GHC] #2076: rational infinities don't compare correctly to each other
GHC
cvs-ghc at haskell.org
Mon Dec 3 21:49:08 CET 2012
#2076: rational infinities don't compare correctly to each other
---------------------------------+------------------------------------------
Reporter: uhollerbach | Owner: jeffrey
Type: bug | Status: new
Priority: normal | Milestone: _|_
Component: libraries/base | Version: 6.8.2
Keywords: | Os: Unknown/Multiple
Architecture: Unknown/Multiple | Failure: None/Unknown
Difficulty: Unknown | Testcase:
Blockedby: | Blocking:
Related: |
---------------------------------+------------------------------------------
Comment(by jeffrey):
In libraries/base/GHC/Real.lhs, I added
{{{
instance (Integral a) => Ord (Ratio a) where
{-# SPECIALIZE instance Ord Rational #-}
+ (x:%0) <= (x':%0 ) = x < 0 || 0 < x'
+ (x:%0) <= (_ :%_ ) = x < 0
+ (_:%_) <= (x':%0 ) = 0 < x'
(x:%y) <= (x':%y') = x * y' <= x' * y
+ (x:%0) < (x':%0 ) = x < 0 && 0 < x'
+ (x:%0) < (_ :%_ ) = x < 0
+ (_:%_) < (x':%0 ) = 0 < x'
(x:%y) < (x':%y') = x * y' < x' * y
}}}
which passes my testsuite for this bug. However, I also tested the
equivalence of same-sign infinities (which I assumed to be a desired
property when I wrote the code) and found that it wasn't working; for
example
{{{
Prelude GHC.Real> (2:%0) == (1:%0)
False
}}}
When I also found that, for example,
{{{
Prelude GHC.Real> (2:%4) == (1:%2)
False
}}}
I figured that (:%) wasn't intended to equate different forms of actually-
equal ratios. So I figured my proposed bug fix would just introduce
another bug, since it, for example, yields
{{{
Prelude GHC.Real> (2:%0) < (1:%0) -- should be False
False
Prelude GHC.Real> (2:%0) <= (1:%0)
True
}}}
which contradicts the non-equality observed above. But then I tried
{{{
Prelude GHC.Real> compare (2:%4) (1:%2)
LT
Prelude GHC.Real> (2:%4) < (1:%2)
False
}}}
which doesn't make sense(?), and figured I'm probably missing the bigger
picture here. Thoughts?
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/2076#comment:6>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the Glasgow-haskell-bugs
mailing list