Search code examples
pythonexponential

Why does one of these code segment work while the other throws an overflow


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


Solution

  • math.pow:

    Unlike the built-in ** operator, math.pow() converts both its arguments to type float. Use ** or the built-in pow() function for computing exact integer powers.