Modulus in Matlab for large numbers without toolbox

I am porting some of my Python code to Matlab and have encountered an issue when doing mod calculations in Matlab, resulting in NaN being returned instead of the correct value like Python.

In Python the code is p = pow(8687205886,5788687615,8369428283) the same in Matlab

a = 8687205886^5788687615
b = 8369428283
m = mod(a,b)

I have no acess to any toolboxes other than the default ones so using the Symbolic Maths Toolbox or alternatives are not an option.

How would such a calcuation be done in Matlab ?

Thank you

4

1 Answer

Lacking the required toolbox for higher precision numbers, using python in MATLAB might be an option:

p = py.pow(int64(8687205886),int64(5788687615),int64(8369428283))
p = Python long with properties: denominator: [1×1 py.long] imag: [1×1 py.long] numerator: [1×1 py.long] real: [1×1 py.long] 539591274

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like