Search code examples
javabigdecimalmodulus

Java - Modulus function fails on large numbers


I am working on RSA algo but the numbers, on which different operations are performed, are very large. And Java operators are failing here.

I need to take modulus of a very large number (like this big 1.35858791876006E+75) but the normal % or bigDecimalObj.divideAndRemainder() function does not give me the correct answer.

Is there any other library (some .jar file) available that could help me out?


Solution

  • You should consider BigInteger, it can handle big numbers. More specifically using mod() and modpow() can solve many overflow issues.