Powermod involving REALLY large integers
2 views (last 30 days)
Show older comments
Yuechuan Chen
on 9 Dec 2019
Commented: Yuechuan Chen
on 9 Dec 2019
So basically I'm trying to use powermod with very big numbers. I have s=1473687476915250164368566014542081756221043781677543142805. when I do powermd(7,s,n) it comes with with an error message:'must be a nonnegative integer.'(see image attached)
I don't see any mistakes in my script, could someone explain to me why this is occuring pls
THANK YOU!
digits 100
n=sym('94315998522576010519588224930693232398146802027362761139521');
a=7;
i=1;
while mod(n-1,2^i)==0
i=i+1;
end
i
r=i-1
s=vpa((n-1)/2^r)
powermod(7,s,n)
0 Comments
Accepted Answer
Walter Roberson
on 9 Dec 2019
Even though you have set digits large enough, s=vpa((n-1)/2^r) always produces a symbolic floating point number because that is what vpa() is defined to do. powermod() cannot work with symbolic floating point numbers.
There are advanced techniques that could force the symbolic engine to convert s from symbolic floating point to symbolic integer, but they are obscure... and they are unnecessary. Just leave out the vpa() part in defining s, just s = (n-1)/2^r
More Answers (0)
See Also
Categories
Find more on Numbers and Precision in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!