Incorrect result with bigNatPowMod
Summary
When trying to use bigNatPowMod
to replace powModInteger
I notice the function sometimes returns incorrect result.
In the GMP backend, bignat_powmod
ignores the result of integer_gmp_powm#
, so does not set the size of the output, possibly leaving uninitialized limbs in the word array.
Steps to reproduce
The following program:
{-# LANGUAGE MagicHash #-}
import GHC.Num.BigNat
import GHC.Num.Integer
main :: IO ()
main =
let b = integerToBigNatClamp# 251943445928310882947152017889649234
e = integerToBigNatClamp# 503886891856621765894304035779298468
m = integerToBigNatClamp# 503886891856621765894304035779298469
r = integerFromBigNat# (bigNatPowMod b e m)
in print r
when executed with runghc
displays a non-constant result like 85639447066539974357520744449.
Expected behavior
Result displayed should be always 1.
Environment
- GHC version used: branch
master
, commite1dc3d7b89ea79aea158ee487234d3730e857f04
.
Optional:
- Operating System: macOS
- System Architecture: x86_64