def power, problem when raising power to decimals

Mark Dickinson dickinsm at gmail.com
Wed Apr 16 16:33:39 EDT 2008


On Apr 16, 4:19 pm, skanem... at yahoo.se wrote:
> how do i solve power(5,1.3)?
>
[...]
>
> also i found a link which states 0^0 isnt 1 even though every
> calculator ive tried says it is.
> it doesnt say what it is but i presume 0 then.
> but it seems the dude is wrong and it is 1?

>>> 5**1.3
8.1032829834638136
>>> 0**0
1
>>> 0.**0.
1.0
>>> from decimal import Decimal
>>> Decimal(0)**Decimal(0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/decimal.py", line 1755, in __pow__
    return context._raise_error(InvalidOperation, '0 ** 0')
  File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/decimal.py", line 2325, in _raise_error
    raise error, explanation
decimal.InvalidOperation: 0 ** 0

Most mathematicians consider 0**0 to be either 1 or undefined.  Which
answer you get depends on who you ask (or in Python, whether you're
working with floats or Decimals, as you see above).

Mark



More information about the Python-list mailing list