[GHC] #9811: constant folding with infinities is wrong

GHC ghc-devs at haskell.org
Tue Nov 18 05:48:14 UTC 2014


#9811: constant folding with infinities is wrong
-------------------------------------+-------------------------------------
       Reporter:  rwbarton           |                   Owner:
           Type:  bug                |                  Status:  new
       Priority:  low                |               Milestone:
      Component:  Compiler           |                 Version:  7.8.3
       Keywords:                     |        Operating System:
   Architecture:  Unknown/Multiple   |  Unknown/Multiple
     Difficulty:  Unknown            |         Type of failure:
     Blocked By:                     |  None/Unknown
Related Tickets:  #9810              |               Test Case:
                                     |                Blocking:
                                     |  Differential Revisions:
-------------------------------------+-------------------------------------
 {{{
 main = let big =
 99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
                   :: Double in
   print (big * big - big * big)
 }}}

 prints NaN when compiled without optimizations but 0.0 when compiled with
 optimizations.

 Or, `print (big * big / 2)` prints Infinity when compiled without
 optimizations but 8.98846567431158e307 when compiled with optimizations
 (this number is `fromRational (toRational (1/0) / 2)`).

 The cause is the conversions that go on between Rational and Double in
 PrelRules (in the functions doubleOp2, mkDoubleVal, convFloating).

 Ideally, we would have an accurate model of floating-point arithmetic on
 the target machine, but for now it would be an improvement to just not
 constant fold when the result is not a finite floating-point number.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9811>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list