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
0c67312c
Commit
0c67312c
authored
Oct 29, 2009
by
Mark Dickinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #7233: A number of two-argument Decimal methods were failing to
accept ints and longs for the second argument.
parent
783b8775
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
70 additions
and
1 deletion
+70
-1
Lib/decimal.py
Lib/decimal.py
+20
-1
Lib/test/test_decimal.py
Lib/test/test_decimal.py
+47
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/decimal.py
View file @
0c67312c
...
...
@@ -2723,6 +2723,8 @@ class Decimal(object):
value. Note that a total ordering is defined for all possible abstract
representations.
"""
other
=
_convert_other
(
other
,
raiseit
=
True
)
# if one is negative and the other is positive, it's easy
if
self
.
_sign
and
not
other
.
_sign
:
return
_NegativeOne
...
...
@@ -2792,6 +2794,8 @@ class Decimal(object):
Like compare_total, but with operand's sign ignored and assumed to be 0.
"""
other
=
_convert_other
(
other
,
raiseit
=
True
)
s
=
self
.
copy_abs
()
o
=
other
.
copy_abs
()
return
s
.
compare_total
(
o
)
...
...
@@ -3160,6 +3164,9 @@ class Decimal(object):
"""Applies an 'and' operation between self and other's digits."""
if
context
is
None
:
context
=
getcontext
()
other
=
_convert_other
(
other
,
raiseit
=
True
)
if
not
self
.
_islogical
()
or
not
other
.
_islogical
():
return
context
.
_raise_error
(
InvalidOperation
)
...
...
@@ -3181,6 +3188,9 @@ class Decimal(object):
"""Applies an 'or' operation between self and other's digits."""
if
context
is
None
:
context
=
getcontext
()
other
=
_convert_other
(
other
,
raiseit
=
True
)
if
not
self
.
_islogical
()
or
not
other
.
_islogical
():
return
context
.
_raise_error
(
InvalidOperation
)
...
...
@@ -3195,6 +3205,9 @@ class Decimal(object):
"""Applies an 'xor' operation between self and other's digits."""
if
context
is
None
:
context
=
getcontext
()
other
=
_convert_other
(
other
,
raiseit
=
True
)
if
not
self
.
_islogical
()
or
not
other
.
_islogical
():
return
context
.
_raise_error
(
InvalidOperation
)
...
...
@@ -3408,6 +3421,8 @@ class Decimal(object):
if
context
is
None
:
context
=
getcontext
()
other
=
_convert_other
(
other
,
raiseit
=
True
)
ans
=
self
.
_check_nans
(
other
,
context
)
if
ans
:
return
ans
...
...
@@ -3432,11 +3447,13 @@ class Decimal(object):
return
_dec_from_triple
(
self
.
_sign
,
rotated
.
lstrip
(
'0'
)
or
'0'
,
self
.
_exp
)
def
scaleb
(
self
,
other
,
context
=
None
):
def
scaleb
(
self
,
other
,
context
=
None
):
"""Returns self operand after adding the second value to its exp."""
if
context
is
None
:
context
=
getcontext
()
other
=
_convert_other
(
other
,
raiseit
=
True
)
ans
=
self
.
_check_nans
(
other
,
context
)
if
ans
:
return
ans
...
...
@@ -3460,6 +3477,8 @@ class Decimal(object):
if
context
is
None
:
context
=
getcontext
()
other
=
_convert_other
(
other
,
raiseit
=
True
)
ans
=
self
.
_check_nans
(
other
,
context
)
if
ans
:
return
ans
...
...
Lib/test/test_decimal.py
View file @
0c67312c
...
...
@@ -1476,6 +1476,53 @@ class DecimalUsabilityTest(unittest.TestCase):
self
.
assertEqual
(
str
(
Decimal
(
0
).
sqrt
()),
str
(
c
.
sqrt
(
Decimal
(
0
))))
def
test_conversions_from_int
(
self
):
# Check that methods taking a second Decimal argument will
# always accept an integer in place of a Decimal.
self
.
assertEqual
(
Decimal
(
4
).
compare
(
3
),
Decimal
(
4
).
compare
(
Decimal
(
3
)))
self
.
assertEqual
(
Decimal
(
4
).
compare_signal
(
3
),
Decimal
(
4
).
compare_signal
(
Decimal
(
3
)))
self
.
assertEqual
(
Decimal
(
4
).
compare_total
(
3
),
Decimal
(
4
).
compare_total
(
Decimal
(
3
)))
self
.
assertEqual
(
Decimal
(
4
).
compare_total_mag
(
3
),
Decimal
(
4
).
compare_total_mag
(
Decimal
(
3
)))
self
.
assertEqual
(
Decimal
(
10101
).
logical_and
(
1001
),
Decimal
(
10101
).
logical_and
(
Decimal
(
1001
)))
self
.
assertEqual
(
Decimal
(
10101
).
logical_or
(
1001
),
Decimal
(
10101
).
logical_or
(
Decimal
(
1001
)))
self
.
assertEqual
(
Decimal
(
10101
).
logical_xor
(
1001
),
Decimal
(
10101
).
logical_xor
(
Decimal
(
1001
)))
self
.
assertEqual
(
Decimal
(
567
).
max
(
123
),
Decimal
(
567
).
max
(
Decimal
(
123
)))
self
.
assertEqual
(
Decimal
(
567
).
max_mag
(
123
),
Decimal
(
567
).
max_mag
(
Decimal
(
123
)))
self
.
assertEqual
(
Decimal
(
567
).
min
(
123
),
Decimal
(
567
).
min
(
Decimal
(
123
)))
self
.
assertEqual
(
Decimal
(
567
).
min_mag
(
123
),
Decimal
(
567
).
min_mag
(
Decimal
(
123
)))
self
.
assertEqual
(
Decimal
(
567
).
next_toward
(
123
),
Decimal
(
567
).
next_toward
(
Decimal
(
123
)))
self
.
assertEqual
(
Decimal
(
1234
).
quantize
(
100
),
Decimal
(
1234
).
quantize
(
Decimal
(
100
)))
self
.
assertEqual
(
Decimal
(
768
).
remainder_near
(
1234
),
Decimal
(
768
).
remainder_near
(
Decimal
(
1234
)))
self
.
assertEqual
(
Decimal
(
123
).
rotate
(
1
),
Decimal
(
123
).
rotate
(
Decimal
(
1
)))
self
.
assertEqual
(
Decimal
(
1234
).
same_quantum
(
1000
),
Decimal
(
1234
).
same_quantum
(
Decimal
(
1000
)))
self
.
assertEqual
(
Decimal
(
'9.123'
).
scaleb
(
-
100
),
Decimal
(
'9.123'
).
scaleb
(
Decimal
(
-
100
)))
self
.
assertEqual
(
Decimal
(
456
).
shift
(
-
1
),
Decimal
(
456
).
shift
(
Decimal
(
-
1
)))
self
.
assertEqual
(
Decimal
(
-
12
).
fma
(
Decimal
(
45
),
67
),
Decimal
(
-
12
).
fma
(
Decimal
(
45
),
Decimal
(
67
)))
self
.
assertEqual
(
Decimal
(
-
12
).
fma
(
45
,
67
),
Decimal
(
-
12
).
fma
(
Decimal
(
45
),
Decimal
(
67
)))
self
.
assertEqual
(
Decimal
(
-
12
).
fma
(
45
,
Decimal
(
67
)),
Decimal
(
-
12
).
fma
(
Decimal
(
45
),
Decimal
(
67
)))
class
DecimalPythonAPItests
(
unittest
.
TestCase
):
...
...
Misc/NEWS
View file @
0c67312c
...
...
@@ -427,6 +427,9 @@ Core and Builtins
Library
-------
- Issue #7233: Fix a number of two-argument Decimal methods to make sure
that they accept an int or long as the second argument.
- Issue #4750: Store the basename of the original filename in the gzip FNAME
header as required by RFC 1952.
...
...
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