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
298131a4
Commit
298131a4
authored
Aug 26, 2014
by
Stefan Krah
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #22090: Fix '%' formatting for infinities and NaNs.
parent
d84fd73d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
4 deletions
+14
-4
Lib/decimal.py
Lib/decimal.py
+2
-0
Lib/test/test_decimal.py
Lib/test/test_decimal.py
+5
-0
Modules/_decimal/libmpdec/io.c
Modules/_decimal/libmpdec/io.c
+7
-4
No files found.
Lib/decimal.py
View file @
298131a4
...
...
@@ -3769,6 +3769,8 @@ class Decimal(object):
if
self
.
_is_special
:
sign
=
_format_sign
(
self
.
_sign
,
spec
)
body
=
str
(
self
.
copy_abs
())
if
spec
[
'type'
]
==
'%'
:
body
+=
'%'
return
_format_align
(
sign
,
body
,
spec
)
# a type of None defaults to 'g' or 'G', depending on context
...
...
Lib/test/test_decimal.py
View file @
298131a4
...
...
@@ -1057,6 +1057,11 @@ class FormatTest(unittest.TestCase):
# issue 6850
(
'a=-7.0'
,
'0.12345'
,
'aaaa0.1'
),
# issue 22090
(
'<^+15.20%'
,
'inf'
,
'<<+Infinity%<<<'
),
(
'
\
x07
>,%'
,
'sNaN1234567'
,
'sNaN1234567%'
),
(
'=10.10%'
,
'NaN123'
,
' NaN123%'
),
]
for
fmt
,
d
,
result
in
test_values
:
self
.
assertEqual
(
format
(
Decimal
(
d
),
fmt
),
result
)
...
...
Modules/_decimal/libmpdec/io.c
View file @
298131a4
...
...
@@ -446,7 +446,7 @@ _mpd_to_string(char **result, const mpd_t *dec, int flags, mpd_ssize_t dplace)
if
(
mpd_isspecial
(
dec
))
{
mem
=
sizeof
"-Infinity"
;
mem
=
sizeof
"-Infinity
%
"
;
if
(
mpd_isnan
(
dec
)
&&
dec
->
len
>
0
)
{
/* diagnostic code */
mem
+=
dec
->
digits
;
...
...
@@ -609,10 +609,10 @@ _mpd_to_string(char **result, const mpd_t *dec, int flags, mpd_ssize_t dplace)
*
cp
++
=
(
flags
&
MPD_FMT_UPPER
)
?
'E'
:
'e'
;
cp
=
exp_to_string
(
cp
,
ldigits
-
dplace
);
}
}
if
(
flags
&
MPD_FMT_PERCENT
)
{
*
cp
++
=
'%'
;
}
if
(
flags
&
MPD_FMT_PERCENT
)
{
*
cp
++
=
'%'
;
}
assert
(
cp
<
decstring
+
mem
);
...
...
@@ -1260,6 +1260,9 @@ mpd_qformat_spec(const mpd_t *dec, const mpd_spec_t *spec,
stackspec
.
align
=
'>'
;
spec
=
&
stackspec
;
}
if
(
type
==
'%'
)
{
flags
|=
MPD_FMT_PERCENT
;
}
}
else
{
uint32_t
workstatus
=
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