#1239: compare on exceptional Doubles and Floats should raise an error
-------------------------------+--------------------------------------------
    Reporter:  igloo           |       Owner:         
        Type:  proposal        |      Status:  new    
    Priority:  normal          |   Milestone:         
   Component:  libraries/base  |     Version:  6.6    
    Severity:  normal          |    Keywords:         
  Difficulty:  Unknown         |    Testcase:         
Architecture:  Unknown         |          Os:  Unknown
-------------------------------+--------------------------------------------
Consider:
 {{{
 let n = 0/0 :: Double in (n `compare` n, n < n, n == n, n > n)
 }}}
 In GHC and YHC this gives
 {{{
 (GT,False,False,False)
 }}}
 while in hugs it gives
 {{{
 (EQ,False,False,False)
 }}}
 Neither of these is very satisfactory, as I would expect
 {{{
 x `compare` y === EQ   =>   (x == y) === True
 x `compare` y === GT   =>   (x > y) === True
 }}}
 and it's even less pleasant that the implementations differ for no good
 reason.

 The Haskell report isn't very helpful on how comparing exceptional
 Doubles should behave, as it doesn't even say you need to have NaN etc:
 {{{
 http://haskell.org/onlinereport/basic.html#sect6.4
 The results of exceptional conditions (such as overflow or
 underflow) on the fixed-precision numeric types are undefined; an
 implementation may choose error (_|_, semantically), a truncated
 value, or a special value such as infinity, indefinite, etc.
 }}}
 I think that the right answer is that
 {{{
 n `compare` n
 }}}
 above
 (and more generally such a comparison for any incomparable Doubles or
 Flaots)
 should raise an error (i.e. be _|_).

 The changes needed are simple, e.g. for GHC
 {{{
 (D# x) `compare` (D# y) | x <## y   = LT
                         | x ==## y  = EQ
                         | otherwise = GT
 }}}
 becomes
 {{{
 (D# x) `compare` (D# y) | x <## y   = LT
                         | x ==## y  = EQ
                         | x >## y   = GT
                         | otherwise = error "Incomparable values"
 }}}

 Deadline: 1 week after discussion ends.

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/1239>
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