math.pow(a,n) versus ** operator
urner at alumni.princeton.edu
Mon Oct 16 08:04:10 CEST 2000
math.pow is clearly more powerful, not barfing
when exponent is a negative number:
>>> math.pow(2,-1) # math.pow(a,-n) == math.pow(1.0/a,n)
Traceback (innermost last):
File "<pyshell#297>", line 1, in ?
ValueError: integer to the negative power
However, ** also seems just plain wrong when raising a
negative to the 0th power:
>>> -1**0 # this is wrong
>>> math.pow(-1,0) # this is correct
Any non-zero number to the 0th power is supposed to be 1.
I can see no justification for this behavior of ** in
returning -1 for -1**0.
More information about the Python-list