[Python-checkins] r61892 - in python/trunk: Lib/decimal.py Lib/test/test_decimal.py Misc/NEWS
mark.dickinson
python-checkins at python.org
Tue Mar 25 15:33:23 CET 2008
Author: mark.dickinson
Date: Tue Mar 25 15:33:23 2008
New Revision: 61892
Modified:
python/trunk/Lib/decimal.py
python/trunk/Lib/test/test_decimal.py
python/trunk/Misc/NEWS
Log:
Issue #2478: Decimal(sqrt(0)) failed when the decimal context
was not explicitly supplied.
Modified: python/trunk/Lib/decimal.py
==============================================================================
--- python/trunk/Lib/decimal.py (original)
+++ python/trunk/Lib/decimal.py Tue Mar 25 15:33:23 2008
@@ -2453,6 +2453,9 @@
def sqrt(self, context=None):
"""Return the square root of self."""
+ if context is None:
+ context = getcontext()
+
if self._is_special:
ans = self._check_nans(context=context)
if ans:
@@ -2466,9 +2469,6 @@
ans = _dec_from_triple(self._sign, '0', self._exp // 2)
return ans._fix(context)
- if context is None:
- context = getcontext()
-
if self._sign == 1:
return context._raise_error(InvalidOperation, 'sqrt(-x), x > 0')
Modified: python/trunk/Lib/test/test_decimal.py
==============================================================================
--- python/trunk/Lib/test/test_decimal.py (original)
+++ python/trunk/Lib/test/test_decimal.py Tue Mar 25 15:33:23 2008
@@ -1315,6 +1315,12 @@
d = d1.max(d2)
self.assertTrue(type(d) is Decimal)
+ def test_implicit_context(self):
+ # Check results when context given implicitly. (Issue 2478)
+ c = getcontext()
+ self.assertEqual(str(Decimal(0).sqrt()),
+ str(c.sqrt(Decimal(0))))
+
class DecimalPythonAPItests(unittest.TestCase):
Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS (original)
+++ python/trunk/Misc/NEWS Tue Mar 25 15:33:23 2008
@@ -72,6 +72,8 @@
Library
-------
+- Issue #2478: fix failure of decimal.Decimal(0).sqrt()
+
- Issue #2432: give DictReader the dialect and line_num attributes
advertised in the docs.
More information about the Python-checkins
mailing list