Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #83396 > unrolled thread
| Started by | Chris Rebert <clp2@rebertia.com> |
|---|---|
| First post | 2015-01-08 18:53 -0800 |
| Last post | 2015-01-08 18:53 -0800 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Decimals and other numbers Chris Rebert <clp2@rebertia.com> - 2015-01-08 18:53 -0800
| From | Chris Rebert <clp2@rebertia.com> |
|---|---|
| Date | 2015-01-08 18:53 -0800 |
| Subject | Re: Decimals and other numbers |
| Message-ID | <mailman.17500.1420772019.18130.python-list@python.org> |
On Thu, Jan 8, 2015 at 6:33 PM, Devin Jeanpierre <jeanpierreda@gmail.com> wrote:
> 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?
The `decimal` std lib module implements the General Decimal Arithmetic
Specification (http://speleotrove.com/decimal/decarith.html ).
In the "Exceptional conditions" section
(http://speleotrove.com/decimal/daexcep.html ), it specifies the
following:
Invalid operation
This occurs and signals invalid-operation if:
[...]
* both operands of the power operation are zero
No idea why it chose to differ from IEEE-754.
Cheers,
Chris
Back to top | Article view | comp.lang.python
csiph-web