Skip to content

Infinite floating point literal not possible

One thing that I have noticed in the past is that it is not possible to embed an efficient floating point literal in one's program. For instance, you might write:

f :: Double -> ...

g = ... f (1/0)

However, GHC will end up floating out the free expression 1/0 to a top-level CAF. This means that you must take a tag check every time you refer to the literal. Surely we can do better than this.

Either we should avoid floating out such simple expressions or we should introduce constant-folding for this case and teach C-- about non-finite floating-point literals.

Other literals:

  • 1/0 -> infinity (this one), similarly for negative infinity
  • 0/0 -> NaN (one particular NaN literal should suffice), originally reported in #20379 (closed)
  • -0.0 -> negative zero. Currently compiles to negateFloat# 0.0#, orginally reported in #20380 (closed).
Edited by Sebastian Graf
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information