Skip to content

constant folding with infinities is wrong

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.

Trac metadata
Trac field Value
Version 7.8.3
Type Bug
TypeOfFailure OtherFailure
Priority low
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information