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
abfedb4e
Commit
abfedb4e
authored
Dec 15, 2012
by
Stefan Krah
Browse files
Options
Browse Files
Download
Plain Diff
Merge 3.3.
parents
21a0b07c
f5c3134b
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
625 additions
and
233 deletions
+625
-233
Doc/library/decimal.rst
Doc/library/decimal.rst
+54
-41
Lib/decimal.py
Lib/decimal.py
+6
-6
Lib/test/test_decimal.py
Lib/test/test_decimal.py
+294
-8
Misc/NEWS
Misc/NEWS
+4
-0
Modules/_decimal/_decimal.c
Modules/_decimal/_decimal.c
+103
-84
Modules/_decimal/docstrings.h
Modules/_decimal/docstrings.h
+112
-94
Modules/_decimal/tests/deccheck.py
Modules/_decimal/tests/deccheck.py
+34
-0
Modules/_decimal/tests/randdec.py
Modules/_decimal/tests/randdec.py
+18
-0
No files found.
Doc/library/decimal.rst
View file @
abfedb4e
This diff is collapsed.
Click to expand it.
Lib/decimal.py
View file @
abfedb4e
...
...
@@ -2594,7 +2594,7 @@ class Decimal(object):
ans
=
ans
.
_fix
(
context
)
return
ans
def
same_quantum
(
self
,
other
):
def
same_quantum
(
self
,
other
,
context
=
None
):
"""Return True if self and other have the same exponent; otherwise
return False.
...
...
@@ -2912,7 +2912,7 @@ class Decimal(object):
except
TypeError
:
return
0
def
canonical
(
self
,
context
=
None
):
def
canonical
(
self
):
"""Returns the same Decimal object.
As we do not have different encodings for the same number, the
...
...
@@ -2932,7 +2932,7 @@ class Decimal(object):
return
ans
return
self
.
compare
(
other
,
context
=
context
)
def
compare_total
(
self
,
other
):
def
compare_total
(
self
,
other
,
context
=
None
):
"""Compares self to other using the abstract representations.
This is not like the standard compare, which use their numerical
...
...
@@ -3005,7 +3005,7 @@ class Decimal(object):
return
_Zero
def
compare_total_mag
(
self
,
other
):
def
compare_total_mag
(
self
,
other
,
context
=
None
):
"""Compares self to other using abstract repr., ignoring sign.
Like compare_total, but with operand's sign ignored and assumed to be 0.
...
...
@@ -3027,7 +3027,7 @@ class Decimal(object):
else
:
return
_dec_from_triple
(
1
,
self
.
_int
,
self
.
_exp
,
self
.
_is_special
)
def
copy_sign
(
self
,
other
):
def
copy_sign
(
self
,
other
,
context
=
None
):
"""Returns self with the sign of other."""
other
=
_convert_other
(
other
,
raiseit
=
True
)
return
_dec_from_triple
(
other
.
_sign
,
self
.
_int
,
...
...
@@ -4180,7 +4180,7 @@ class Context(object):
"""
if
not
isinstance
(
a
,
Decimal
):
raise
TypeError
(
"canonical requires a Decimal as an argument."
)
return
a
.
canonical
(
context
=
self
)
return
a
.
canonical
()
def
compare
(
self
,
a
,
b
):
"""Compares values numerically.
...
...
Lib/test/test_decimal.py
View file @
abfedb4e
This diff is collapsed.
Click to expand it.
Misc/NEWS
View file @
abfedb4e
...
...
@@ -167,6 +167,10 @@ Core and Builtins
Library
-------
- Issue #15783: Except for the number methods, the C version of decimal now
supports all None default values present in decimal.py. These values were
largely undocumented.
- Issue #11175: argparse.FileType now accepts encoding and errors
arguments. Patch by Lucas Maystre.
...
...
Modules/_decimal/_decimal.c
View file @
abfedb4e
This diff is collapsed.
Click to expand it.
Modules/_decimal/docstrings.h
View file @
abfedb4e
This diff is collapsed.
Click to expand it.
Modules/_decimal/tests/deccheck.py
View file @
abfedb4e
...
...
@@ -36,6 +36,7 @@ from copy import copy
from
collections
import
defaultdict
from
test.support
import
import_fresh_module
from
randdec
import
randfloat
,
all_unary
,
all_binary
,
all_ternary
from
randdec
import
unary_optarg
,
binary_optarg
,
ternary_optarg
from
formathelper
import
rand_format
,
rand_locale
C
=
import_fresh_module
(
'decimal'
,
fresh
=
[
'_decimal'
])
...
...
@@ -834,6 +835,17 @@ def test_unary(method, prec, exp_range, restricted_range, itr, stat):
except
VerifyError
as
err
:
log
(
err
)
if
not
method
.
startswith
(
'__'
):
for
op
in
unary_optarg
(
prec
,
exp_range
,
itr
):
t
=
TestSet
(
method
,
op
)
try
:
if
not
convert
(
t
):
continue
callfuncs
(
t
)
verify
(
t
,
stat
)
except
VerifyError
as
err
:
log
(
err
)
def
test_binary
(
method
,
prec
,
exp_range
,
restricted_range
,
itr
,
stat
):
"""Iterate a binary function through many test cases."""
if
method
in
BinaryRestricted
:
...
...
@@ -848,6 +860,17 @@ def test_binary(method, prec, exp_range, restricted_range, itr, stat):
except
VerifyError
as
err
:
log
(
err
)
if
not
method
.
startswith
(
'__'
):
for
op
in
binary_optarg
(
prec
,
exp_range
,
itr
):
t
=
TestSet
(
method
,
op
)
try
:
if
not
convert
(
t
):
continue
callfuncs
(
t
)
verify
(
t
,
stat
)
except
VerifyError
as
err
:
log
(
err
)
def
test_ternary
(
method
,
prec
,
exp_range
,
restricted_range
,
itr
,
stat
):
"""Iterate a ternary function through many test cases."""
if
method
in
TernaryRestricted
:
...
...
@@ -862,6 +885,17 @@ def test_ternary(method, prec, exp_range, restricted_range, itr, stat):
except
VerifyError
as
err
:
log
(
err
)
if
not
method
.
startswith
(
'__'
):
for
op
in
ternary_optarg
(
prec
,
exp_range
,
itr
):
t
=
TestSet
(
method
,
op
)
try
:
if
not
convert
(
t
):
continue
callfuncs
(
t
)
verify
(
t
,
stat
)
except
VerifyError
as
err
:
log
(
err
)
def
test_format
(
method
,
prec
,
exp_range
,
restricted_range
,
itr
,
stat
):
"""Iterate the __format__ method through many test cases."""
for
op
in
all_unary
(
prec
,
exp_range
,
itr
):
...
...
Modules/_decimal/tests/randdec.py
View file @
abfedb4e
...
...
@@ -527,6 +527,11 @@ def all_unary(prec, exp_range, itr):
for
_
in
range
(
100
):
yield
(
randtuple
(
prec
,
exp_range
),)
def
unary_optarg
(
prec
,
exp_range
,
itr
):
for
_
in
range
(
100
):
yield
randdec
(
prec
,
exp_range
),
None
yield
randdec
(
prec
,
exp_range
),
None
,
None
def
all_binary
(
prec
,
exp_range
,
itr
):
for
a
,
b
in
bin_close_to_pow10
(
prec
,
exp_range
,
itr
):
yield
a
,
b
...
...
@@ -543,6 +548,11 @@ def all_binary(prec, exp_range, itr):
for
_
in
range
(
100
):
yield
randdec
(
prec
,
exp_range
),
randdec
(
prec
,
exp_range
)
def
binary_optarg
(
prec
,
exp_range
,
itr
):
for
_
in
range
(
100
):
yield
randdec
(
prec
,
exp_range
),
randdec
(
prec
,
exp_range
),
None
yield
randdec
(
prec
,
exp_range
),
randdec
(
prec
,
exp_range
),
None
,
None
def
all_ternary
(
prec
,
exp_range
,
itr
):
for
a
,
b
,
c
in
tern_close_numbers
(
prec
,
exp_range
,
-
exp_range
,
itr
):
yield
a
,
b
,
c
...
...
@@ -557,3 +567,11 @@ def all_ternary(prec, exp_range, itr):
b
=
randdec
(
prec
,
2
*
exp_range
)
c
=
randdec
(
prec
,
2
*
exp_range
)
yield
a
,
b
,
c
def
ternary_optarg
(
prec
,
exp_range
,
itr
):
for
_
in
range
(
100
):
a
=
randdec
(
prec
,
2
*
exp_range
)
b
=
randdec
(
prec
,
2
*
exp_range
)
c
=
randdec
(
prec
,
2
*
exp_range
)
yield
a
,
b
,
c
,
None
yield
a
,
b
,
c
,
None
,
None
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