Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d314e1b

Browse files
committed
Merged revisions 74564 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r74564 | mark.dickinson | 2009-08-28 14:25:02 +0100 (Fri, 28 Aug 2009) | 3 lines Issue #6794: Fix handling of NaNs in Decimal.compare_total and Decimal.compare_total_mag. ........
1 parent 5e129db commit d314e1b

3 files changed

Lines changed: 24 additions & 2 deletions

File tree

Lib/decimal.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2819,12 +2819,15 @@ def compare_total(self, other):
28192819
other_nan = other._isnan()
28202820
if self_nan or other_nan:
28212821
if self_nan == other_nan:
2822-
if self._int < other._int:
2822+
# compare payloads as though they're integers
2823+
self_key = len(self._int), self._int
2824+
other_key = len(other._int), other._int
2825+
if self_key < other_key:
28232826
if sign:
28242827
return _One
28252828
else:
28262829
return _NegativeOne
2827-
if self._int > other._int:
2830+
if self_key > other_key:
28282831
if sign:
28292832
return _NegativeOne
28302833
else:

Lib/test/decimaltestdata/extra.decTest

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,22 @@ extr1301 fma Inf 0 sNaN456 -> NaN Invalid_operation
154154
extr1302 fma 0E123 -Inf sNaN789 -> NaN Invalid_operation
155155
extr1302 fma -Inf 0E-456 sNaN148 -> NaN Invalid_operation
156156

157+
-- Issue #6794: when comparing NaNs using compare_total, payloads
158+
-- should be compared as though positive integers; not
159+
-- lexicographically as strings.
160+
extr1400 comparetotal NaN123 NaN45 -> 1
161+
extr1401 comparetotal sNaN123 sNaN45 -> 1
162+
extr1402 comparetotal -NaN123 -NaN45 -> -1
163+
extr1403 comparetotal -sNaN123 -sNaN45 -> -1
164+
extr1404 comparetotal NaN45 NaN123 -> -1
165+
extr1405 comparetotal sNaN45 sNaN123 -> -1
166+
extr1406 comparetotal -NaN45 -NaN123 -> 1
167+
extr1407 comparetotal -sNaN45 -sNaN123 -> 1
168+
169+
extr1410 comparetotal -sNaN63450748854172416 -sNaN911993 -> -1
170+
extr1411 comparetotmag NaN1222222222222 -NaN999999 -> 1
171+
172+
157173
-- max/min/max_mag/min_mag bug in 2.5.2/2.6/3.0: max(NaN, finite) gave
158174
-- incorrect answers when the finite number required rounding; similarly
159175
-- for the other thre functions

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ C-API
6565
Library
6666
-------
6767

68+
- Issue #6794: Fix Decimal.compare_total and Decimal.compare_total_mag: NaN
69+
payloads are now ordered by integer value rather than lexicographically.
70+
6871
- Issue #1356969: Add missing info methods in tix.HList.
6972

7073
- Issue #1522587: New constants and methods for the tix.Grid widget.

0 commit comments

Comments
 (0)