diff options
author | Christian Heimes <christian@cheimes.de> | 2008-03-26 12:55:56 (GMT) |
---|---|---|
committer | Christian Heimes <christian@cheimes.de> | 2008-03-26 12:55:56 (GMT) |
commit | 0348fb6d1955ca1ebeabf5db053a4781b41d16d6 (patch) | |
tree | b57d29fc6bbbfe91484f105a41e6aaf9def101ea /Lib | |
parent | 44471f3c55c1811de0fc46ac06b99304e71eda98 (diff) | |
download | cpython-0348fb6d1955ca1ebeabf5db053a4781b41d16d6.zip cpython-0348fb6d1955ca1ebeabf5db053a4781b41d16d6.tar.gz cpython-0348fb6d1955ca1ebeabf5db053a4781b41d16d6.tar.bz2 |
Merged revisions 61892,61900 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r61892 | mark.dickinson | 2008-03-25 15:33:23 +0100 (Tue, 25 Mar 2008) | 3 lines
Issue #2478: Decimal(sqrt(0)) failed when the decimal context
was not explicitly supplied.
........
r61900 | georg.brandl | 2008-03-25 18:36:43 +0100 (Tue, 25 Mar 2008) | 2 lines
Add Benjamin.
........
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/decimal.py | 6 | ||||
-rw-r--r-- | Lib/test/test_decimal.py | 6 |
2 files changed, 9 insertions, 3 deletions
diff --git a/Lib/decimal.py b/Lib/decimal.py index 75a1d5e..a2e7fa4 100644 --- a/Lib/decimal.py +++ b/Lib/decimal.py @@ -2454,6 +2454,9 @@ class Decimal(_numbers.Real): 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: @@ -2467,9 +2470,6 @@ class Decimal(_numbers.Real): 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') diff --git a/Lib/test/test_decimal.py b/Lib/test/test_decimal.py index 7c607f9..a76b505 100644 --- a/Lib/test/test_decimal.py +++ b/Lib/test/test_decimal.py @@ -1303,6 +1303,12 @@ class DecimalUsabilityTest(unittest.TestCase): 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): |