diff options
author | Sylvain Henry <sylvain@haskus.fr> | 2021-06-03 11:31:49 +0200 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-06-19 12:27:12 -0400 |
commit | 8838241f7d672a58522b902c89c9149d6197bb72 (patch) | |
tree | 1fe1a8fb00448f8436bc64bbde99edadaf4d5db1 /libraries | |
parent | 217b4dcc004faffd3c7f5d15ba002dcfb0d1027e (diff) | |
download | haskell-8838241f7d672a58522b902c89c9149d6197bb72.tar.gz |
Fix naturalToFloat/Double
* move naturalToFloat/Double from ghc-bignum to base:GHC.Float and make
them wired-in (as their integerToFloat/Double counterparts)
* use the same rounding method as integerToFloat/Double. This is an
oversight of 540fa6b2cff3802877ff56a47ab3611e33a9ac86
* add passthrough rules for intToFloat, intToDouble, wordToFloat,
wordToDouble.
Diffstat (limited to 'libraries')
-rw-r--r-- | libraries/base/GHC/Float.hs | 15 | ||||
-rw-r--r-- | libraries/ghc-bignum/changelog.md | 4 | ||||
-rw-r--r-- | libraries/ghc-bignum/ghc-bignum.cabal | 2 | ||||
-rw-r--r-- | libraries/ghc-bignum/src/GHC/Num/Natural.hs | 9 |
4 files changed, 20 insertions, 10 deletions
diff --git a/libraries/base/GHC/Float.hs b/libraries/base/GHC/Float.hs index acca5118ab..e1dbe03010 100644 --- a/libraries/base/GHC/Float.hs +++ b/libraries/base/GHC/Float.hs @@ -309,6 +309,13 @@ integerToFloat# i@(IP _) = case integerToBinaryFloat' i of integerToFloat# (IN bn) = case integerToBinaryFloat' (IP bn) of F# x -> negateFloat# x +-- | Convert a Natural to a Float# +naturalToFloat# :: Natural -> Float# +{-# NOINLINE naturalToFloat# #-} +naturalToFloat# (NS w) = word2Float# w +naturalToFloat# (NB b) = case integerToBinaryFloat' (IP b) of + F# x -> x + -- | @since 2.01 instance Real Float where toRational (F# x#) = @@ -530,6 +537,14 @@ integerToDouble# i@(IP _) = case integerToBinaryFloat' i of integerToDouble# (IN bn) = case integerToBinaryFloat' (IP bn) of D# x -> negateDouble# x +-- | Encode a Natural (mantissa) into a Double# +naturalToDouble# :: Natural -> Double# +{-# NOINLINE naturalToDouble# #-} +naturalToDouble# (NS w) = word2Double# w +naturalToDouble# (NB b) = case integerToBinaryFloat' (IP b) of + D# x -> x + + -- | @since 2.01 instance Real Double where toRational (D# x#) = diff --git a/libraries/ghc-bignum/changelog.md b/libraries/ghc-bignum/changelog.md index 55cbef72b3..68f98d3adc 100644 --- a/libraries/ghc-bignum/changelog.md +++ b/libraries/ghc-bignum/changelog.md @@ -1,5 +1,9 @@ # Changelog for `ghc-bignum` package +## 1.2 + +- Moved naturalToDouble# and naturalToFloat# to `base` package + ## 1.1 - Moved integerToDouble# and integerToFloat# to `base` package with fixed diff --git a/libraries/ghc-bignum/ghc-bignum.cabal b/libraries/ghc-bignum/ghc-bignum.cabal index 6de0328c49..468c2a042a 100644 --- a/libraries/ghc-bignum/ghc-bignum.cabal +++ b/libraries/ghc-bignum/ghc-bignum.cabal @@ -1,6 +1,6 @@ cabal-version: 2.0 name: ghc-bignum -version: 1.1 +version: 1.2 synopsis: GHC BigNum library license: BSD3 license-file: LICENSE diff --git a/libraries/ghc-bignum/src/GHC/Num/Natural.hs b/libraries/ghc-bignum/src/GHC/Num/Natural.hs index 55aee2d2f7..38a20f5169 100644 --- a/libraries/ghc-bignum/src/GHC/Num/Natural.hs +++ b/libraries/ghc-bignum/src/GHC/Num/Natural.hs @@ -132,19 +132,10 @@ naturalEncodeDouble# (NS w) 0# = word2Double# w naturalEncodeDouble# (NS w) e = wordEncodeDouble# w e naturalEncodeDouble# (NB b) e = bigNatEncodeDouble# b e --- | Encode a Natural (mantissa) into a Double# -naturalToDouble# :: Natural -> Double# -naturalToDouble# !n = naturalEncodeDouble# n 0# - --- | Encode a Natural (mantissa) into a Float# -naturalToFloat# :: Natural -> Float# -naturalToFloat# !i = naturalEncodeFloat# i 0# - -- | Encode (# Natural mantissa, Int# exponent #) into a Float# -- -- TODO: Not sure if it's worth to write 'Float' optimized versions here naturalEncodeFloat# :: Natural -> Int# -> Float# -naturalEncodeFloat# !m 0# = double2Float# (naturalToDouble# m) naturalEncodeFloat# !m e = double2Float# (naturalEncodeDouble# m e) -- | Equality test for Natural |