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
edd13fcc
Commit
edd13fcc
authored
Jul 04, 2019
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix small number rounding with fixed precision in grisu
parent
6a031347
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
2 additions
and
0 deletions
+2
-0
include/fmt/format-inl.h
include/fmt/format-inl.h
+1
-0
test/grisu-test.cc
test/grisu-test.cc
+1
-0
No files found.
include/fmt/format-inl.h
View file @
edd13fcc
...
@@ -604,6 +604,7 @@ struct fixed_handler {
...
@@ -604,6 +604,7 @@ struct fixed_handler {
// Check if precision is satisfied just by leading zeros, e.g.
// Check if precision is satisfied just by leading zeros, e.g.
// format("{:.2f}", 0.001) gives "0.00" without generating any digits.
// format("{:.2f}", 0.001) gives "0.00" without generating any digits.
if
(
precision
>
0
)
return
digits
::
more
;
if
(
precision
>
0
)
return
digits
::
more
;
if
(
precision
<
0
)
return
digits
::
done
;
auto
dir
=
get_round_direction
(
divisor
,
remainder
,
error
);
auto
dir
=
get_round_direction
(
divisor
,
remainder
,
error
);
if
(
dir
==
unknown
)
return
digits
::
error
;
if
(
dir
==
unknown
)
return
digits
::
error
;
buf
[
size
++
]
=
dir
==
up
?
'1'
:
'0'
;
buf
[
size
++
]
=
dir
==
up
?
'1'
:
'0'
;
...
...
test/grisu-test.cc
View file @
edd13fcc
...
@@ -40,6 +40,7 @@ TEST(GrisuTest, Zero) { EXPECT_EQ("0.0", fmt::format("{}", 0.0)); }
...
@@ -40,6 +40,7 @@ TEST(GrisuTest, Zero) { EXPECT_EQ("0.0", fmt::format("{}", 0.0)); }
TEST
(
GrisuTest
,
Round
)
{
TEST
(
GrisuTest
,
Round
)
{
EXPECT_EQ
(
"1.9156918820264798e-56"
,
EXPECT_EQ
(
"1.9156918820264798e-56"
,
fmt
::
format
(
"{}"
,
1.9156918820264798e-56
));
fmt
::
format
(
"{}"
,
1.9156918820264798e-56
));
EXPECT_EQ
(
"0.0000"
,
fmt
::
format
(
"{:.4f}"
,
7.2809479766055470e-15
));
}
}
TEST
(
GrisuTest
,
Prettify
)
{
TEST
(
GrisuTest
,
Prettify
)
{
...
...
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