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
6d1dece0
Commit
6d1dece0
authored
Feb 14, 2017
by
Andrew Nester
Committed by
Mark Dickinson
Feb 14, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed #29534 - _decimal difference with _pydecimal (#65)
parent
c33ee85b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
11 deletions
+28
-11
Lib/_pydecimal.py
Lib/_pydecimal.py
+16
-11
Lib/test/test_decimal.py
Lib/test/test_decimal.py
+10
-0
Misc/NEWS
Misc/NEWS
+2
-0
No files found.
Lib/_pydecimal.py
View file @
6d1dece0
...
...
@@ -734,18 +734,23 @@ class Decimal(object):
"""
if
isinstance
(
f
,
int
):
# handle integer inputs
return
cls
(
f
)
if
not
isinstance
(
f
,
float
):
raise
TypeError
(
"argument must be int or float."
)
if
_math
.
isinf
(
f
)
or
_math
.
isnan
(
f
):
return
cls
(
repr
(
f
))
if
_math
.
copysign
(
1.0
,
f
)
==
1.0
:
sign
=
0
sign
=
0
if
f
>=
0
else
1
k
=
0
coeff
=
str
(
abs
(
f
))
elif
isinstance
(
f
,
float
):
if
_math
.
isinf
(
f
)
or
_math
.
isnan
(
f
):
return
cls
(
repr
(
f
))
if
_math
.
copysign
(
1.0
,
f
)
==
1.0
:
sign
=
0
else
:
sign
=
1
n
,
d
=
abs
(
f
).
as_integer_ratio
()
k
=
d
.
bit_length
()
-
1
coeff
=
str
(
n
*
5
**
k
)
else
:
sign
=
1
n
,
d
=
abs
(
f
).
as_integer_ratio
()
k
=
d
.
bit_length
()
-
1
result
=
_dec_from_triple
(
sign
,
str
(
n
*
5
**
k
),
-
k
)
raise
TypeError
(
"argument must be int or float."
)
result
=
_dec_from_triple
(
sign
,
coeff
,
-
k
)
if
cls
is
Decimal
:
return
result
else
:
...
...
Lib/test/test_decimal.py
View file @
6d1dece0
...
...
@@ -1185,6 +1185,16 @@ class FormatTest(unittest.TestCase):
self
.
assertEqual
(
format
(
Decimal
(
'100000000.123'
),
'n'
),
'100
\
u066c
000
\
u066c
000
\
u066b
123'
)
def
test_decimal_from_float_argument_type
(
self
):
class
A
(
self
.
decimal
.
Decimal
):
def
__init__
(
self
,
a
):
self
.
a_type
=
type
(
a
)
a
=
A
.
from_float
(
42.5
)
self
.
assertEqual
(
self
.
decimal
.
Decimal
,
a
.
a_type
)
a
=
A
.
from_float
(
42
)
self
.
assertEqual
(
self
.
decimal
.
Decimal
,
a
.
a_type
)
class
CFormatTest
(
FormatTest
):
decimal
=
C
class
PyFormatTest
(
FormatTest
):
...
...
Misc/NEWS
View file @
6d1dece0
...
...
@@ -10,6 +10,8 @@ What's New in Python 3.7.0 alpha 1?
Core and Builtins
-----------------
- bpo-29534: Fixed different behaviour of Decimal.from_float() for _decimal and _pydecimal.
- bpo-29438: Fixed use-after-free problem in key sharing dict.
- Issue #29319: Prevent RunMainFromImporter overwriting sys.path[0].
...
...
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