# how to handle big numbers

• August 13th, 2013, 01:50 PM
veera
how to handle big numbers
How to handle a big number value like
Math.pow(41,77) gives a large value and I needs to take mod( % ) of that value. So I directly write a stmt as Math.pow(41,77)%119;
The correct result of this equation is 6(I know its the correct ans. *check it by calculator ). But my code returns 88 so what's wrong in my code?
How can I rewrite the same code to get the correct output.
• August 13th, 2013, 02:22 PM
copeg
Re: how to handle big numbers
Use a BigInteger to prevent the overflow of an int
• August 13th, 2013, 10:06 PM
veera
Re: how to handle big numbers
Integer can hold 6 right? Why we need to go for big integer ?
The value of Math.pow(41,77) is 1.5 E124 this value can hold in double variable.
• August 13th, 2013, 10:49 PM
helloworld922
Re: how to handle big numbers
A double variable doesn't hold every single digit of 1.5e124. It holds a fixed "mantissa" which is ~16 digits, and an integer exponent.