numberToRangedRational: fix edge cases for exp ≈ (maxBound :: Int)
Currently a negative exponent less than `minBound :: Int` results in Infinity, which is very surprising and obviously wrong. ``` λ> read "1e-9223372036854775808" :: Double 0.0 λ> read "1e-9223372036854775809" :: Double Infinity ``` There is a further edge case where the exponent can overflow when increased by the number of tens places in the integer part, or underflow when decreased by the number of leading zeros in the fractional part if the integer part is zero: ``` λ> read "10e9223372036854775807" :: Double 0.0 λ> read "0.01e-9223372036854775808" :: Double Infinity ``` To resolve both of these issues, perform all arithmetic and comparisons involving the exponent in type `Integer`. This approach also eliminates the need to explicitly check the exponent against `maxBound :: Int` and `minBound :: Int`, because the allowed range of the exponent (i.e. the result of `floatRange` for the target floating point type) is certainly within those bounds. This change implements CLC proposal 192: https://github.com/haskell/core-libraries-committee/issues/192
Showing
- libraries/base/Text/Read/Lex.hs 8 additions, 10 deletionslibraries/base/Text/Read/Lex.hs
- libraries/base/changelog.md 1 addition, 0 deletionslibraries/base/changelog.md
- libraries/base/tests/all.T 1 addition, 0 deletionslibraries/base/tests/all.T
- libraries/base/tests/read-float-double.hs 20 additions, 0 deletionslibraries/base/tests/read-float-double.hs
- libraries/base/tests/read-float-double.stdout 8 additions, 0 deletionslibraries/base/tests/read-float-double.stdout
Loading
Please register or sign in to comment