mirror of
https://github.com/python/cpython.git
synced 2025-08-19 08:11:46 +00:00
Decimal.sqrt(0) failed when the context was not
explicitly supplied.
This commit is contained in:
parent
a79e05097b
commit
26c25d9f64
3 changed files with 11 additions and 3 deletions
|
@ -2316,6 +2316,9 @@ class Decimal(object):
|
|||
|
||||
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:
|
||||
|
@ -2329,9 +2332,6 @@ class Decimal(object):
|
|||
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')
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue