Merged revisions 74566 via svnmerge from
authorMark Dickinson <dickinsm@gmail.com>
Fri, 28 Aug 2009 13:44:35 +0000 (13:44 +0000)
committerMark Dickinson <dickinsm@gmail.com>
Fri, 28 Aug 2009 13:44:35 +0000 (13:44 +0000)
svn+ssh://pythondev@www.python.org/python/branches/py3k

................
  r74566 | mark.dickinson | 2009-08-28 14:39:53 +0100 (Fri, 28 Aug 2009) | 10 lines

  Merged revisions 74564 via svnmerge from
  svn+ssh://pythondev@svn.python.org/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.
  ........
................

Lib/decimal.py
Lib/test/decimaltestdata/extra.decTest
Misc/NEWS

index 042dd8bd856298c32e130d2593047441785f2d03..8d82cb9f578b5e32fd74fefd20b8b33ccaed5007 100644 (file)
@@ -2819,12 +2819,15 @@ class Decimal(object):
         other_nan = other._isnan()
         if self_nan or other_nan:
             if self_nan == other_nan:
-                if self._int < other._int:
+                # compare payloads as though they're integers
+                self_key = len(self._int), self._int
+                other_key = len(other._int), other._int
+                if self_key < other_key:
                     if sign:
                         return _One
                     else:
                         return _NegativeOne
-                if self._int > other._int:
+                if self_key > other_key:
                     if sign:
                         return _NegativeOne
                     else:
index 2e3fce85585c3b70351ab1bdfd99ec37aa3ca82b..1d6ea3702ad89f0c0ea8ad89beb3ee13a18f46e0 100644 (file)
@@ -154,6 +154,22 @@ extr1301 fma Inf 0 sNaN456 -> NaN Invalid_operation
 extr1302 fma 0E123 -Inf sNaN789 -> NaN Invalid_operation
 extr1302 fma -Inf 0E-456 sNaN148 -> NaN Invalid_operation
 
+-- Issue #6794: when comparing NaNs using compare_total, payloads
+-- should be compared as though positive integers; not
+-- lexicographically as strings.
+extr1400 comparetotal NaN123 NaN45 -> 1
+extr1401 comparetotal sNaN123 sNaN45 -> 1
+extr1402 comparetotal -NaN123 -NaN45 -> -1
+extr1403 comparetotal -sNaN123 -sNaN45 -> -1
+extr1404 comparetotal NaN45 NaN123 -> -1
+extr1405 comparetotal sNaN45 sNaN123 -> -1
+extr1406 comparetotal -NaN45 -NaN123 -> 1
+extr1407 comparetotal -sNaN45 -sNaN123 -> 1
+
+extr1410 comparetotal -sNaN63450748854172416 -sNaN911993 -> -1
+extr1411 comparetotmag NaN1222222222222 -NaN999999 -> 1
+
+
 -- max/min/max_mag/min_mag bug in 2.5.2/2.6/3.0: max(NaN, finite) gave
 -- incorrect answers when the finite number required rounding; similarly
 -- for the other thre functions
index 099f73a116790ae825c7ada02619ed0ded4b0dfe..da8cdf500c782b1d8ed15efcc6a5a54cbbc56af5 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -47,6 +47,9 @@ C-API
 Library
 -------
 
+- Issue #6794: Fix Decimal.compare_total and Decimal.compare_total_mag: NaN
+  payloads are now ordered by integer value rather than lexicographically.
+
 - Issue #6106: telnetlib.Telnet.process_rawq doesn't handle default WILL/WONT
   DO/DONT correctly.