Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
26c25d9f
Commit
26c25d9f
authored
Mar 25, 2008
by
Mark Dickinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Decimal.sqrt(0) failed when the context was not
explicitly supplied.
parent
a79e0509
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
3 deletions
+11
-3
Lib/decimal.py
Lib/decimal.py
+3
-3
Lib/test/test_decimal.py
Lib/test/test_decimal.py
+6
-0
Misc/NEWS
Misc/NEWS
+2
-0
No files found.
Lib/decimal.py
View file @
26c25d9f
...
@@ -2316,6 +2316,9 @@ class Decimal(object):
...
@@ -2316,6 +2316,9 @@ class Decimal(object):
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
:
...
@@ -2329,9 +2332,6 @@ class Decimal(object):
...
@@ -2329,9 +2332,6 @@ class Decimal(object):
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'
)
...
...
Lib/test/test_decimal.py
View file @
26c25d9f
...
@@ -1192,6 +1192,12 @@ class DecimalUsabilityTest(unittest.TestCase):
...
@@ -1192,6 +1192,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
):
...
...
Misc/NEWS
View file @
26c25d9f
...
@@ -27,6 +27,8 @@ Core and builtins
...
@@ -27,6 +27,8 @@ Core and builtins
Library
Library
-------
-------
- Issue #2478: fix failure of decimal.Decimal(0).sqrt()
- Issue #2432: give DictReader the dialect and line_num attributes
- Issue #2432: give DictReader the dialect and line_num attributes
advertised in the docs.
advertised in the docs.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment