MATLAB: How to get mod of large numbers

mod

I have this calculation: c=(5652)^42.(23)^77mod5929, when i use scientific calculator I get c=4624 an when I do this by MATLAB mod command it gives 0…why?

Best Answer

If you compute (5652^42)*(23^77) to use the naive approach for computing this quantity, the resulting number is much greater than flintmax. If we look at the spacing between that number and the next largest number, we see that the spacing is (much) greater than 5929.
>> x = (5652^42)*(23^77)
x =
2.78954779454946e+262
>> eps(x)
ans =
3.49595995098571e+246
>> (x + 5929) == x
ans =
logical
1
As Sean stated in this answer from a while ago, you could use Symbolic Math Toolbox. Or you could use one of the algorithms described in this Wikipedia page to perform these computations with numbers no greater than 5652^2.