Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
fmt
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
fmt
Commits
28d7191c
Commit
28d7191c
authored
Nov 24, 2019
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't print trailing zero with fixed, precision=0, and showpoint (#1417)
parent
43271ba8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
5 deletions
+10
-5
include/fmt/format.h
include/fmt/format.h
+9
-5
test/format-test.cc
test/format-test.cc
+1
-0
No files found.
include/fmt/format.h
View file @
28d7191c
...
@@ -1136,9 +1136,14 @@ template <typename Char> class float_writer {
...
@@ -1136,9 +1136,14 @@ template <typename Char> class float_writer {
// 1234e7 -> 12340000000[.0+]
// 1234e7 -> 12340000000[.0+]
it
=
copy_str
<
Char
>
(
digits_
,
digits_
+
num_digits_
,
it
);
it
=
copy_str
<
Char
>
(
digits_
,
digits_
+
num_digits_
,
it
);
it
=
std
::
fill_n
(
it
,
full_exp
-
num_digits_
,
static_cast
<
Char
>
(
'0'
));
it
=
std
::
fill_n
(
it
,
full_exp
-
num_digits_
,
static_cast
<
Char
>
(
'0'
));
int
num_zeros
=
(
std
::
max
)(
params_
.
num_digits
-
full_exp
,
1
);
if
(
params_
.
trailing_zeros
)
{
if
(
params_
.
trailing_zeros
)
{
*
it
++
=
decimal_point_
;
*
it
++
=
decimal_point_
;
int
num_zeros
=
params_
.
num_digits
-
full_exp
;
if
(
num_zeros
<=
0
)
{
if
(
params_
.
format
!=
float_format
::
fixed
)
*
it
++
=
static_cast
<
Char
>
(
'0'
);
return
it
;
}
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
if
(
num_zeros
>
1000
)
if
(
num_zeros
>
1000
)
throw
std
::
runtime_error
(
"fuzz mode - avoiding excessive cpu use"
);
throw
std
::
runtime_error
(
"fuzz mode - avoiding excessive cpu use"
);
...
@@ -1191,10 +1196,9 @@ template <typename Char> class float_writer {
...
@@ -1191,10 +1196,9 @@ template <typename Char> class float_writer {
decimal_point_
(
decimal_point
)
{
decimal_point_
(
decimal_point
)
{
int
full_exp
=
num_digits
+
exp
-
1
;
int
full_exp
=
num_digits
+
exp
-
1
;
int
precision
=
params
.
num_digits
>
0
?
params
.
num_digits
:
16
;
int
precision
=
params
.
num_digits
>
0
?
params
.
num_digits
:
16
;
if
(
params_
.
format
==
float_format
::
general
)
{
if
(
params_
.
format
==
float_format
::
general
&&
params_
.
format
=
full_exp
>=
-
4
&&
full_exp
<
precision
!
(
full_exp
>=
-
4
&&
full_exp
<
precision
))
{
?
float_format
::
fixed
params_
.
format
=
float_format
::
exp
;
:
float_format
::
exp
;
}
}
size_
=
prettify
(
counting_iterator
()).
count
();
size_
=
prettify
(
counting_iterator
()).
count
();
size_
+=
params_
.
sign
?
1
:
0
;
size_
+=
params_
.
sign
?
1
:
0
;
...
...
test/format-test.cc
View file @
28d7191c
...
@@ -1212,6 +1212,7 @@ TEST(FormatterTest, Precision) {
...
@@ -1212,6 +1212,7 @@ TEST(FormatterTest, Precision) {
"012970999954193198940908041656332452475714786901472678015935523861155013"
"012970999954193198940908041656332452475714786901472678015935523861155013"
"480352649347201937902681071074917033322268447533357208324319361e-324"
,
"480352649347201937902681071074917033322268447533357208324319361e-324"
,
format
(
"{:.494}"
,
4.9406564584124654E-324
));
format
(
"{:.494}"
,
4.9406564584124654E-324
));
EXPECT_EQ
(
"123."
,
format
(
"{:#.0f}"
,
123.0
));
EXPECT_THROW_MSG
(
format
(
"{0:.2}"
,
reinterpret_cast
<
void
*>
(
0xcafe
)),
EXPECT_THROW_MSG
(
format
(
"{0:.2}"
,
reinterpret_cast
<
void
*>
(
0xcafe
)),
format_error
,
format_error
,
...
...
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