I am working with python and I am trying to find powers of really large numbers but something interesting which happens is that this throws a math overflow
math.pow(1000, 1000)
but this below seems to work although I do not know if the value returned is correct
1000**1000
Anybody aware why this happens
Simple, the math.pow()
method uses C float libraries, while the **
power operator uses integer maths.
The two methods have different limitations. Python int
size is only limited by how much memory your OS will let Python have, float numbers are limited by your computer architecture, see sys.float_info.max
.
math.pow:
Unlike the built-in
**
operator,math.pow()
converts both its arguments to typefloat
. Use**
or the built-inpow()
function for computing exact integer powers.
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