Change representation of Floating literals
Not using Rational
everywhere makes it easy and convenient to less wrongly handle odd cases like NaN, +/-Infinity, and negative zero in these literals. This resolves #18897 and should facilitate any potential further work on #8364 by localizing the necessary changes to GHC.Types.Literal
.
Floating-point operations involving zero are no longer constant-folded with unlimited precision when -fexcess-precision
is set, but otherwise its behavior should be unchanged.
- The main point of this MR is the new
LitFloating
type and its operations defined inGHC.Types.Literal.Floating
. Most of the other compiler files are changed only to use and convert to/from this new type where it is appropriate to do so. - Several parts of
GHC.Core.Opt.ConstantFold
are moved around or combined. Some of this rearrangement is to move calculations intoGHC.Types.Literal
, some of this is to allow the appropriateConstantFoldingPrecision
to be selected for every floating-point calculation, and some of this is to unify its treatment ofFloat
andDouble
. - The changes related to
base:GHC.Float.rationalToDouble
are to prevent WW from breaking constant-folding on this function. (This patch allows1/0
and friends to be constant-folded, so that this function no longer needs to return its result boxed.)