diff options
author | Sylvain Henry <sylvain@haskus.fr> | 2020-09-16 10:59:57 +0200 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2020-09-17 20:04:46 -0400 |
commit | b689f3db0229ac58af5383796fb13c6d40e358ce (patch) | |
tree | bc83554a3e23205b0896adf88d9e93846c087ec3 /libraries/ghc-bignum/src | |
parent | 7f2785f2d6c6947d22d4d8b71d205c7c4b025680 (diff) | |
download | haskell-b689f3db0229ac58af5383796fb13c6d40e358ce.tar.gz |
Bignum: add clamping naturalToWord (fix #18697)
Diffstat (limited to 'libraries/ghc-bignum/src')
-rw-r--r-- | libraries/ghc-bignum/src/GHC/Num/Natural.hs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/libraries/ghc-bignum/src/GHC/Num/Natural.hs b/libraries/ghc-bignum/src/GHC/Num/Natural.hs index 62e9f33e1c..d5e91c9574 100644 --- a/libraries/ghc-bignum/src/GHC/Num/Natural.hs +++ b/libraries/ghc-bignum/src/GHC/Num/Natural.hs @@ -107,6 +107,14 @@ naturalToWord# (NB b) = bigNatIndex# b 0# naturalToWord :: Natural -> Word naturalToWord !n = W# (naturalToWord# n) +-- | Convert a Natural into a Word# clamping to (maxBound :: Word#). +naturalToWordClamp# :: Natural -> Word# +naturalToWordClamp# (NS x) = x +naturalToWordClamp# (NB _) = WORD_MAXBOUND## + +-- | Convert a Natural into a Word# clamping to (maxBound :: Word). +naturalToWordClamp :: Natural -> Word +naturalToWordClamp !n = W# (naturalToWordClamp# n) -- | Try downcasting 'Natural' to 'Word' value. -- Returns '()' if value doesn't fit in 'Word'. |