[issue15544] math.isnan fails with some Decimal NaNs

2012-08-24 Thread Roundup Robot
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

[issue15544] math.isnan fails with some Decimal NaNs

2012-08-24 Thread Roundup Robot
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

[issue15544] math.isnan fails with some Decimal NaNs

2012-08-24 Thread Roundup Robot
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

[issue15544] math.isnan fails with some Decimal NaNs

2012-08-24 Thread Mark Dickinson
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

[issue15544] math.isnan fails with some Decimal NaNs

2012-08-19 Thread Mark Dickinson
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

[issue15544] math.isnan fails with some Decimal NaNs

2012-08-19 Thread Stefan Krah
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 ___

[issue15544] math.isnan fails with some Decimal NaNs

2012-08-08 Thread Raymond Hettinger
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).

[issue15544] math.isnan fails with some Decimal NaNs

2012-08-04 Thread Mark Dickinson
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

[issue15544] math.isnan fails with some Decimal NaNs

2012-08-04 Thread Stefan Krah
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

[issue15544] math.isnan fails with some Decimal NaNs

2012-08-04 Thread Steven D'Aprano
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

[issue15544] math.isnan fails with some Decimal NaNs

2012-08-03 Thread Mark Dickinson
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

[issue15544] math.isnan fails with some Decimal NaNs

2012-08-03 Thread Steven D'Aprano
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

[issue15544] math.isnan fails with some Decimal NaNs

2012-08-03 Thread Stefan Krah
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)

[issue15544] math.isnan fails with some Decimal NaNs

2012-08-03 Thread Mark Dickinson
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

[issue15544] math.isnan fails with some Decimal NaNs

2012-08-03 Thread Mark Dickinson
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

[issue15544] math.isnan fails with some Decimal NaNs

2012-08-03 Thread Steven D'Aprano
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

[issue15544] math.isnan fails with some Decimal NaNs

2012-08-03 Thread Mark Dickinson
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

[issue15544] math.isnan fails with some Decimal NaNs

2012-08-03 Thread Antoine Pitrou
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 ___

[issue15544] math.isnan fails with some Decimal NaNs

2012-08-03 Thread Stefan Krah
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

[issue15544] math.isnan fails with some Decimal NaNs

2012-08-03 Thread Stefan Krah
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. -- ___

[issue15544] math.isnan fails with some Decimal NaNs

2012-08-03 Thread Antoine Pitrou
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

[issue15544] math.isnan fails with some Decimal NaNs

2012-08-02 Thread Steven D'Aprano
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

[issue15544] math.isnan fails with some Decimal NaNs

2012-08-02 Thread Steven D'Aprano
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 ___

[issue15544] math.isnan fails with some Decimal NaNs

2012-08-02 Thread Ezio Melotti
Changes by Ezio Melotti ezio.melo...@gmail.com: -- nosy: +mark.dickinson, skrah ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue15544 ___ ___