Skip to content

Change representation of Floating literals

Matthew Craven requested to merge clyring/ghc:wip-floating-literal-repr into master

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 in GHC.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 into GHC.Types.Literal, some of this is to allow the appropriate ConstantFoldingPrecision to be selected for every floating-point calculation, and some of this is to unify its treatment of Float and Double.
  • The changes related to base:GHC.Float.rationalToDouble are to prevent WW from breaking constant-folding on this function. (This patch allows 1/0 and friends to be constant-folded, so that this function no longer needs to return its result boxed.)
Edited by Matthew Craven

Merge request reports