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
97619e27
Commit
97619e27
authored
Mar 15, 2019
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More fixed precision tests
parent
dd6cc0e6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
3 deletions
+8
-3
include/fmt/format-inl.h
include/fmt/format-inl.h
+2
-3
test/format-test.cc
test/format-test.cc
+6
-0
No files found.
include/fmt/format-inl.h
View file @
97619e27
...
...
@@ -588,7 +588,7 @@ struct fixed_handler {
}
digits
::
result
on_digit
(
char
digit
,
uint64_t
divisor
,
uint64_t
remainder
,
uint64_t
error
,
int
&
exp
,
bool
integral
)
{
uint64_t
error
,
int
,
bool
integral
)
{
FMT_ASSERT
(
remainder
<
divisor
,
""
);
buf
[
size
++
]
=
digit
;
if
(
size
!=
precision
)
return
digits
::
more
;
...
...
@@ -601,7 +601,6 @@ struct fixed_handler {
FMT_ASSERT
(
error
==
1
&&
divisor
>
2
,
""
);
}
auto
dir
=
get_round_direction
(
divisor
,
remainder
,
error
);
// TODO: test rounding
if
(
dir
!=
up
)
return
dir
==
down
?
digits
::
done
:
digits
::
error
;
++
buf
[
size
-
1
];
for
(
int
i
=
size
-
1
;
i
>
0
&&
buf
[
i
]
>
'9'
;
--
i
)
{
...
...
@@ -610,7 +609,7 @@ struct fixed_handler {
}
if
(
buf
[
0
]
>
'9'
)
{
buf
[
0
]
=
'1'
;
++
exp
;
buf
[
size
++
]
=
'0'
;
}
return
digits
::
done
;
}
...
...
test/format-test.cc
View file @
97619e27
...
...
@@ -1476,7 +1476,13 @@ TEST(FormatterTest, PrecisionRounding) {
EXPECT_EQ
(
"0.001"
,
format
(
"{:.3f}"
,
0.0005
));
EXPECT_EQ
(
"0.001"
,
format
(
"{:.3f}"
,
0.00149
));
EXPECT_EQ
(
"0.002"
,
format
(
"{:.3f}"
,
0.0015
));
EXPECT_EQ
(
"1.000"
,
format
(
"{:.3f}"
,
0.9999
));
EXPECT_EQ
(
"0.00123"
,
format
(
"{:.3}"
,
0.00123
));
// Trigger rounding error in Grisu by a carefully chosen number.
auto
n
=
3788512123356.985352
;
char
buffer
[
64
];
sprintf
(
buffer
,
"%f"
,
n
);
EXPECT_EQ
(
buffer
,
format
(
"{:f}"
,
n
));
}
TEST
(
FormatterTest
,
FormatNaN
)
{
...
...
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