New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make Decimal comparisons with NaN less arbitrary #46271
Comments
For Python 3.0 the decimal module got rich comparisons. Those comparisons have somewhat unconventional The Decimal specification has nothing helpful to say about comparisons involving NaNs. But reading IEEE- (1) have comparisons involving NaNs (except for !=) raise InvalidOperation in the context, and hence give a (2) have comparisons involving NaNs always return False (except for !=, which always returns True). I think either of these is better than the current behavior. (2) seems like the better option, for a couple Since Mike Cowlishaw is intimately involved with both the Decimal specification and the IEEE-754r process, I The attached patch makes <, <=, >, >= and == comparisons involving NaNs always return False, and != Here's how NaN comparisons currently work: Python 3.0a2+ (py3k:60470M, Jan 30 2008, 23:11:40)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from decimal import *
>>> n = Decimal("nan")
>>> i = Decimal("inf")
>>> n < n
False
>>> n > n
True
>>> i < n
False
>>> i > n
True See also issue bpo-1514428. |
ISTM, you're now moving far beyond the spec into territory that isn't |
Yes, I think it's necessary. Speaking of standards, it's the current behavior which isn't backed by any The proposed behavior is much closer to that specified by C99 (see sections The current behavior also breaks something fundamental: namely, that x < y >>> 2 < Decimal("NaN")
True
>>> Decimal(2) < Decimal("NaN")
False |
Here's a patch (richcmp_signal.patch) that gives an alternative way of doing things: all So the post-patch decimal exactly follows IEEE 754(r) on this. I think it makes good sense My worries about list membership testing were nonsensical: there's only one reasonable On balance, I think I prefer this approach to the idea of returning False on comparisons |
I'm +0 regarding this. If this will go in, a comment should explicit all this in the code, as Thanks! |
Okay: I checked in this change in r60630. The checkin includes comments |
Thanks Mark! Shall this issue be closed? |
Closing. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: