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

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

Elena Rostova

Elena Rostova

Lead Health, Wellness & Medical Journalist

Elena Rostova holds a Master's degree in Public Health Journalism. She covers groundbreaking medical research, holistic wellness trends, mental health awareness, and nutritional science.

Share this article
Twitter Facebook Pinterest