diff --git a/src/Cryptol/PrimeEC.hs b/src/Cryptol/PrimeEC.hs index 026f2f82d..e86771ba3 100644 --- a/src/Cryptol/PrimeEC.hs +++ b/src/Cryptol/PrimeEC.hs @@ -47,12 +47,6 @@ module Cryptol.PrimeEC ) where -{- -import GHC.Num.BigNat (BigNat#) -import qualified GHC.Num.Backend as BN -import qualified GHC.Num.BigNat as BN -import qualified GHC.Num.Integer as BN --} import GHC.Num.Compat (BigNat#) import qualified GHC.Num.Compat as BN import GHC.Exts diff --git a/src/GHC/Num/Compat.hs b/src/GHC/Num/Compat.hs index 8c96a6a8a..84ed6abbe 100644 --- a/src/GHC/Num/Compat.hs +++ b/src/GHC/Num/Compat.hs @@ -52,6 +52,9 @@ import GHC.Exts bigNatToInteger :: BigNat# -> Integer bigNatToInteger = Integer.integerFromBigNat# +-- | @'integerRecipMod' x m@ computes the modular inverse of @x@ mod @m@. +-- +-- PRECONDITION: @m@ must be strictly positive. integerRecipMod :: Integer -> Integer -> Maybe Integer integerRecipMod x y = case Integer.integerRecipMod# x (Integer.integerToNaturalClamp y) of @@ -134,6 +137,9 @@ integerToBigNat (GMP.S# i) = GMP.wordToBigNat (int2Word# i) integerToBigNat (GMP.Jp# b) = b integerToBigNat (GMP.Jn# b) = b +-- | @'integerRecipMod' x m@ computes the modular inverse of @x@ mod @m@. +-- +-- PRECONDITION: @m@ must be strictly positive. integerRecipMod :: Integer -> Integer -> Maybe Integer integerRecipMod x y | res == 0 = Nothing