mirror of https://github.com/python/cpython
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. ........
This commit is contained in:
parent
44471f3c55
commit
0348fb6d19
|
@ -2454,6 +2454,9 @@ class Decimal(_numbers.Real):
|
||||||
|
|
||||||
def sqrt(self, context=None):
|
def sqrt(self, context=None):
|
||||||
"""Return the square root of self."""
|
"""Return the square root of self."""
|
||||||
|
if context is None:
|
||||||
|
context = getcontext()
|
||||||
|
|
||||||
if self._is_special:
|
if self._is_special:
|
||||||
ans = self._check_nans(context=context)
|
ans = self._check_nans(context=context)
|
||||||
if ans:
|
if ans:
|
||||||
|
@ -2467,9 +2470,6 @@ class Decimal(_numbers.Real):
|
||||||
ans = _dec_from_triple(self._sign, '0', self._exp // 2)
|
ans = _dec_from_triple(self._sign, '0', self._exp // 2)
|
||||||
return ans._fix(context)
|
return ans._fix(context)
|
||||||
|
|
||||||
if context is None:
|
|
||||||
context = getcontext()
|
|
||||||
|
|
||||||
if self._sign == 1:
|
if self._sign == 1:
|
||||||
return context._raise_error(InvalidOperation, 'sqrt(-x), x > 0')
|
return context._raise_error(InvalidOperation, 'sqrt(-x), x > 0')
|
||||||
|
|
||||||
|
|
|
@ -1303,6 +1303,12 @@ class DecimalUsabilityTest(unittest.TestCase):
|
||||||
d = d1.max(d2)
|
d = d1.max(d2)
|
||||||
self.assertTrue(type(d) is Decimal)
|
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):
|
class DecimalPythonAPItests(unittest.TestCase):
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,9 @@ the format to accommodate documentation needs as they arise.
|
||||||
Permissions History
|
Permissions History
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
|
- Benjamin Peterson was given SVN access on 25 March 2008 by Georg
|
||||||
|
Brandl, for bug triage work.
|
||||||
|
|
||||||
- Jerry Seutter was given SVN access on 20 March 2008 by BAC, for
|
- Jerry Seutter was given SVN access on 20 March 2008 by BAC, for
|
||||||
general contributions to Python.
|
general contributions to Python.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue