i have problems with Math.pow in c# return infinity for example :
double a=65;
double b=331;
Console.Write(Math.Pow(a,b));
//but return infinty
but calculator for my pc not return 65 ^ 331 infinity there are real number return this :1.1866456424809823888425970808655e+600
i use cast to (long) but the result not same windows calculator please i need the variable type is return same window calculator
double has a limited range; it cannot store this number.
Use BigInteger.
Math.pow has a limited range it can function with. See the MSDN docs for more details.
I'm not sure why you're trying to calculate 65^331. One work-around would be to use the BigInteger class:
BigInteger result = new BigInteger(Math.pow(65, 331))
If that doesn't work, there's always good ol' fashioned multiplication:
BigInteger product = 1;
BigInteger a = 65;
for (int i = 0; i < 331; i++) {
product = BigInteger.Multiply(product, a);
}
This should return the value you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With