I've used Math.pow()
to calculate the exponential value in my project.
Now, For specific values like Math.pow(3,40)
, it returns 12157665459056929000
.
But when i tried the same value using a scientific Calculator, it returns 12157665459056928801
.
Then i tried to traverse the loop till the exponential value :
function calculateExpo(base,power){
base = parseInt(base);
power = parseInt(power);
var output = 1;
gameObj.OutPutString = ''; //base + '^' + power + ' = ';
for(var i=0;i<power;i++){
output *= base;
gameObj.OutPutString += base + ' x ';
}
// to remove the last comma
gameObj.OutPutString = gameObj.OutPutString.substring(0,gameObj.OutPutString.lastIndexOf('x'));
gameObj.OutPutString += ' = ' + output;
return output;
}
This also returns 12157665459056929000
.
Is there any restriction to Int type in JS ?