[Git][ghc/ghc][master] Bignum: add clamping naturalToWord (fix #18697)
Marge Bot
gitlab at gitlab.haskell.org
Fri Sep 18 00:04:52 UTC 2020
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
b689f3db by Sylvain Henry at 2020-09-17T20:04:46-04:00
Bignum: add clamping naturalToWord (fix #18697)
- - - - -
1 changed file:
- libraries/ghc-bignum/src/GHC/Num/Natural.hs
Changes:
=====================================
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'.
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/b689f3db0229ac58af5383796fb13c6d40e358ce
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/b689f3db0229ac58af5383796fb13c6d40e358ce
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20200917/db68e77e/attachment-0001.html>
More information about the ghc-commits
mailing list