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
b5eacc29
Commit
b5eacc29
authored
Apr 12, 2011
by
Alexander Belopolsky
Browse files
Options
Browse Files
Download
Plain Diff
Merge
parents
ec78bc8e
1a20c121
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
17 deletions
+16
-17
Lib/decimal.py
Lib/decimal.py
+14
-17
Misc/NEWS
Misc/NEWS
+2
-0
No files found.
Lib/decimal.py
View file @
b5eacc29
...
...
@@ -1650,7 +1650,7 @@ class Decimal(object):
self
=
_dec_from_triple
(
self
.
_sign
,
'1'
,
exp_min
-
1
)
digits
=
0
rounding_method
=
self
.
_pick_rounding_function
[
context
.
rounding
]
changed
=
getattr
(
self
,
rounding_method
)(
digits
)
changed
=
rounding_method
(
self
,
digits
)
coeff
=
self
.
_int
[:
digits
]
or
'0'
if
changed
>
0
:
coeff
=
str
(
int
(
coeff
)
+
1
)
...
...
@@ -1690,8 +1690,6 @@ class Decimal(object):
# here self was representable to begin with; return unchanged
return
Decimal
(
self
)
_pick_rounding_function
=
{}
# for each of the rounding functions below:
# self is a finite, nonzero Decimal
# prec is an integer satisfying 0 <= prec < len(self._int)
...
...
@@ -1758,6 +1756,17 @@ class Decimal(object):
else
:
return
-
self
.
_round_down
(
prec
)
_pick_rounding_function
=
dict
(
ROUND_DOWN
=
_round_down
,
ROUND_UP
=
_round_up
,
ROUND_HALF_UP
=
_round_half_up
,
ROUND_HALF_DOWN
=
_round_half_down
,
ROUND_HALF_EVEN
=
_round_half_even
,
ROUND_CEILING
=
_round_ceiling
,
ROUND_FLOOR
=
_round_floor
,
ROUND_05UP
=
_round_05up
,
)
def
__round__
(
self
,
n
=
None
):
"""Round self to the nearest integer, or to a given precision.
...
...
@@ -2554,8 +2563,8 @@ class Decimal(object):
if
digits
<
0
:
self
=
_dec_from_triple
(
self
.
_sign
,
'1'
,
exp
-
1
)
digits
=
0
this_function
=
getattr
(
self
,
self
.
_pick_rounding_function
[
rounding
])
changed
=
this_function
(
digits
)
this_function
=
self
.
_pick_rounding_function
[
rounding
]
changed
=
this_function
(
self
,
digits
)
coeff
=
self
.
_int
[:
digits
]
or
'0'
if
changed
==
1
:
coeff
=
str
(
int
(
coeff
)
+
1
)
...
...
@@ -3767,18 +3776,6 @@ _numbers.Number.register(Decimal)
##### Context class #######################################################
# get rounding method function:
rounding_functions
=
[
name
for
name
in
Decimal
.
__dict__
.
keys
()
if
name
.
startswith
(
'_round_'
)]
for
name
in
rounding_functions
:
# name is like _round_half_even, goes to the global ROUND_HALF_EVEN value.
globalname
=
name
[
1
:].
upper
()
val
=
globals
()[
globalname
]
Decimal
.
_pick_rounding_function
[
val
]
=
name
del
name
,
val
,
globalname
,
rounding_functions
class
_ContextManager
(
object
):
"""Context manager class to support localcontext().
...
...
Misc/NEWS
View file @
b5eacc29
...
...
@@ -103,6 +103,8 @@ Core and Builtins
Library
-------
- Issue #11830: Remove unnecessary introspection code in the decimal module.
- Issue #11703 - urllib2.geturl() does not return correct url when the original
url contains #fragment.
...
...
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