]> granicus.if.org Git - python/commitdiff
Issue #4084: Fix max, min, max_mag and min_mag Decimal methods to
authorFacundo Batista <facundobatista@gmail.com>
Thu, 11 Dec 2008 04:20:07 +0000 (04:20 +0000)
committerFacundo Batista <facundobatista@gmail.com>
Thu, 11 Dec 2008 04:20:07 +0000 (04:20 +0000)
give correct results in the case where one argument is a quiet NaN
and the other is a finite number that requires rounding.
Thanks Mark Dickinson.

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

index 7fb9c7b82e82486b9cd52ee2bc3be02cd1982774..83ca02042c9cbb3ef0c253df0f93bf49894f02fb 100644 (file)
@@ -2651,10 +2651,10 @@ class Decimal(_numbers.Real):
             sn = self._isnan()
             on = other._isnan()
             if sn or on:
-                if on == 1 and sn != 2:
-                    return self._fix_nan(context)
-                if sn == 1 and on != 2:
-                    return other._fix_nan(context)
+                if on == 1 and sn == 0:
+                    return self._fix(context)
+                if sn == 1 and on == 0:
+                    return other._fix(context)
                 return self._check_nans(other, context)
 
         c = self._cmp(other)
@@ -2693,10 +2693,10 @@ class Decimal(_numbers.Real):
             sn = self._isnan()
             on = other._isnan()
             if sn or on:
-                if on == 1 and sn != 2:
-                    return self._fix_nan(context)
-                if sn == 1 and on != 2:
-                    return other._fix_nan(context)
+                if on == 1 and sn == 0:
+                    return self._fix(context)
+                if sn == 1 and on == 0:
+                    return other._fix(context)
                 return self._check_nans(other, context)
 
         c = self._cmp(other)
@@ -3251,10 +3251,10 @@ class Decimal(_numbers.Real):
             sn = self._isnan()
             on = other._isnan()
             if sn or on:
-                if on == 1 and sn != 2:
-                    return self._fix_nan(context)
-                if sn == 1 and on != 2:
-                    return other._fix_nan(context)
+                if on == 1 and sn == 0:
+                    return self._fix(context)
+                if sn == 1 and on == 0:
+                    return other._fix(context)
                 return self._check_nans(other, context)
 
         c = self.copy_abs()._cmp(other.copy_abs())
@@ -3281,10 +3281,10 @@ class Decimal(_numbers.Real):
             sn = self._isnan()
             on = other._isnan()
             if sn or on:
-                if on == 1 and sn != 2:
-                    return self._fix_nan(context)
-                if sn == 1 and on != 2:
-                    return other._fix_nan(context)
+                if on == 1 and sn == 0:
+                    return self._fix(context)
+                if sn == 1 and on == 0:
+                    return other._fix(context)
                 return self._check_nans(other, context)
 
         c = self.copy_abs()._cmp(other.copy_abs())
index 0cc1bbb5113ee44430f71cadfc1c041cb3f403f7..2e3fce85585c3b70351ab1bdfd99ec37aa3ca82b 100644 (file)
@@ -154,6 +154,23 @@ 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
 
+-- 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
+maxexponent: 999
+minexponent: -999
+precision: 6
+rounding: half_even
+extr1400 max NaN 1234567 -> 1.23457E+6 Inexact Rounded
+extr1401 max 3141590E-123 NaN1729 -> 3.14159E-117 Rounded
+extr1402 max -7.654321 -NaN -> -7.65432 Inexact Rounded
+extr1410 min -NaN -765432.1 -> -765432 Inexact Rounded
+extr1411 min 3141592 NaN -> 3.14159E+6 Inexact Rounded
+extr1420 max_mag 0.1111111 -NaN123 -> 0.111111 Inexact Rounded
+extr1421 max_mag NaN999999999 0.001234567 -> 0.00123457 Inexact Rounded
+extr1430 min_mag 9181716151 -NaN -> 9.18172E+9 Inexact Rounded
+extr1431 min_mag NaN4 1.818180E100 -> 1.81818E+100 Rounded
+
 -- Tests for the is_* boolean operations
 precision: 9
 maxExponent: 999
index 01a592792d5953490ac4eb70c74f7f334d978b6d..eadf9c650e5db58edb9c4801ff2567ef2f6ca558 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -38,6 +38,10 @@ Core and Builtins
 Library
 -------
 
+- Issue #4084: Fix max, min, max_mag and min_mag Decimal methods to
+  give correct results in the case where one argument is a quiet NaN
+  and the other is a finite number that requires rounding.
+
 - Issue #4483: _dbm module now builds on systems with gdbm & gdbm_compat
   libs.