Roundup Robot added the comment:
New changeset 49014c59b31f by Mark Dickinson in branch 'default':
Issue #15544: Fix Decimal.__float__ to work with payload-carrying NaNs.
http://hg.python.org/cpython/rev/49014c59b31f
--
nosy: +python-dev
___
Python
Roundup Robot added the comment:
New changeset a931e44ffbe1 by Mark Dickinson in branch '3.2':
Issue #15544: Fix Decimal.__float__ to work with payload-carrying NaNs.
http://hg.python.org/cpython/rev/a931e44ffbe1
--
___
Python tracker
Roundup Robot added the comment:
New changeset 5dd5f824428c by Mark Dickinson in branch '2.7':
Issue #15544: Fix Decimal.__float__ to work with payload-carrying NaNs.
http://hg.python.org/cpython/rev/5dd5f824428c
--
___
Python tracker
Mark Dickinson added the comment:
Fixed. (I managed to mess up the commit to 3.2 and break all the buildbots
:-(. I think it's okay now.)
Thanks Steven for the report and patch! (And thanks Stefan for reviewing.)
--
resolution: - fixed
status: open - closed
Mark Dickinson added the comment:
Here's an updated patch that extends Steven's fix to the C code.
--
Added file: http://bugs.python.org/file26893/decimalnan_2.patch
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue15544
Stefan Krah added the comment:
The patch looks good in every detail. +1 for committing.
--
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue15544
___
Raymond Hettinger added the comment:
-0.5 on making the math module functions aware of decimals.
The math module was originally conceived as thin wrapper around the C math
library. Subsequently, it has had feature creep (I'm guilty of putting the
integer factorial method in this module).
Mark Dickinson added the comment:
Why not add a is_nan() method to float numbers instead?
That could work. The duplication of float.is_nan and math.isnan (not to
mention the different spellings) would be a bit ugly, but perhaps worth it. It
would make sense to add float.is_infinite and
Stefan Krah added the comment:
Mark Dickinson rep...@bugs.python.org wrote:
Looks like we've got two separate issues here, that should probably be
split into two separate bug reports. The first issue is that
Decimal.__float__ is brain-dead when it comes to NaNs with payloads;
I consider
Steven D'Aprano added the comment:
On 05/08/12 03:45, Mark Dickinson wrote:
It would make sense to add float.is_infinite and (possibly) float.is_finite
methods at the same time.
If you don't add is_finite, you know someone is going to express surprise that
it wasn't already done. Just as
Mark Dickinson added the comment:
Yep, Decimal.__float__ isn't too sophisticated. Probably it should convert all
Decimal quiet NaNs (at least) to float NaNs, keeping the sign if possible but
discarding any payload.
Not so sure about signaling NaNs, though; I think it would be fine for those
Steven D'Aprano added the comment:
Attached is a patch for decimal.py, and test_decimal.py. I cannot provide a
patch for the C decimal implementation, sorry.
Following Mark's suggestion, my patch keeps the sign but discards the payload
for quiet NANs, and raises ValueError for signalling
Stefan Krah added the comment:
I think math.isnan('snan') probably should not raise. Decimal('snan').is_nan()
just returns true and I am under the impression that IEEE 754 specifies the
same. I have to admit though that I just consulted Wikipedia for the latter:
The predicate isNaN(x)
Mark Dickinson added the comment:
Decimal('snan').is_nan()
just returns true and I am under the impression that IEEE 754 specifies the
same.
Sure, but IEEE 754 also specifies that math.sqrt(signalling nan) should
signal. Since both math.sqrt and math.isnan are going through __float__, we
Mark Dickinson added the comment:
IEEE 754 doesn't help here, since it doesn't cover decimal
floating-point - binary floating-point conversions.
OTOH, IEEE 754 *does* cover floating-point to int conversions (5.4.1, 5.8):
those fall under 'general-computational operations', and as such
Steven D'Aprano added the comment:
On 03/08/12 22:06, Mark Dickinson wrote:
Decimal('snan').is_nan() just returns true and I am under the impression
that IEEE 754 specifies the same.
Sure, but IEEE 754 also specifies that math.sqrt(signalling nan) should
signal. Since both math.sqrt and
Mark Dickinson added the comment:
before the conversion to float. By I have no idea whether that is
practical in the math module.
That's a much bigger discussion: as it is, most of the math module functions
just provide simple wrappers around the system math library, which deals purely
Antoine Pitrou added the comment:
Why not add a is_nan() method to float numbers instead?
--
nosy: +pitrou
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue15544
___
Stefan Krah added the comment:
OTOH, IEEE 754 *does* cover floating-point to int conversions (5.4.1, 5.8):
those fall under 'general-computational operations', and as such should
signal when given an sNaN.
That sounds good. Let's keep the ValueError then. We could consider
Stefan Krah added the comment:
Why not add a is_nan() method to float numbers instead?
Do you mean replacing math.isnan(x) by x.is_nan() to avoid the issue
altogether? I'm not sure that's possible given that math just wraps
the C library.
--
___
Antoine Pitrou added the comment:
Why not add a is_nan() method to float numbers instead?
Do you mean replacing math.isnan(x) by x.is_nan() to avoid the issue
altogether? I'm not sure that's possible given that math just wraps
the C library.
Yup. By calling x.is_nan() you would by
New submission from Steven D'Aprano:
math.nan fails on some Decimal NANs. For example, while this works:
import math
from decimal import Decimal
math.isnan(Decimal('nan'))
True
These both fail with ValueError:
math.isnan(Decimal('snan'))
math.isnan(Decimal('nan123'))
(Tested
Changes by Steven D'Aprano steve+pyt...@pearwood.info:
--
components: +Library (Lib)
type: - behavior
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue15544
___
Changes by Ezio Melotti ezio.melo...@gmail.com:
--
nosy: +mark.dickinson, skrah
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue15544
___
___
24 matches
Mail list logo