Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #83392

Decimals and other numbers

From Devin Jeanpierre <jeanpierreda@gmail.com>
Date 2015-01-08 18:33 -0800
Subject Decimals and other numbers
Newsgroups comp.lang.python
Message-ID <mailman.17496.1420770843.18130.python-list@python.org> (permalink)

Show all headers | View raw


I noticed some very PHP-ish behavior today:

>>> import decimal
>>> x = 0
>>> y = float(x)
>>> z = decimal.Decimal(x)
>>> x == y == z == x
True
>>> x ** x
1
>>> y**y
1.0
>>> z**z
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/decimal.py", line 2216, in __pow__
    return context._raise_error(InvalidOperation, '0 ** 0')
  File "/usr/lib/python2.7/decimal.py", line 3872, in _raise_error
    raise error(explanation)
decimal.InvalidOperation: 0 ** 0


I'd file a bug report but I'm anticipating some rational (heh)
explanation. Any ideas?

Python 3.4 also raises this exception, but the error message is less
informative. ("decimal.InvalidOperation: [<class
'decimal.InvalidOperation'>]").

-- Devin

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Decimals and other numbers Devin Jeanpierre <jeanpierreda@gmail.com> - 2015-01-08 18:33 -0800

csiph-web