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
7ffa62db
Commit
7ffa62db
authored
Nov 25, 2019
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix precision handling in snprintf_float
parent
0d07db12
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
3 deletions
+7
-3
include/fmt/format-inl.h
include/fmt/format-inl.h
+7
-3
No files found.
include/fmt/format-inl.h
View file @
7ffa62db
...
@@ -1118,7 +1118,7 @@ int snprintf_float(T value, int precision, float_spec spec, buffer<char>& buf) {
...
@@ -1118,7 +1118,7 @@ int snprintf_float(T value, int precision, float_spec spec, buffer<char>& buf) {
// Subtract 1 to account for the difference in precision since we use %e for
// Subtract 1 to account for the difference in precision since we use %e for
// both general and exponent format.
// both general and exponent format.
if
(
spec
.
format
==
float_format
::
general
)
if
(
spec
.
format
==
float_format
::
general
||
spec
.
format
==
float_format
::
exp
)
precision
=
(
precision
>=
0
?
precision
:
6
)
-
1
;
precision
=
(
precision
>=
0
?
precision
:
6
)
-
1
;
// Build the format string.
// Build the format string.
...
@@ -1127,7 +1127,7 @@ int snprintf_float(T value, int precision, float_spec spec, buffer<char>& buf) {
...
@@ -1127,7 +1127,7 @@ int snprintf_float(T value, int precision, float_spec spec, buffer<char>& buf) {
char
*
format_ptr
=
format
;
char
*
format_ptr
=
format
;
*
format_ptr
++
=
'%'
;
*
format_ptr
++
=
'%'
;
if
(
spec
.
alt
)
*
format_ptr
++
=
'#'
;
if
(
spec
.
alt
)
*
format_ptr
++
=
'#'
;
if
(
precision
>
0
)
{
if
(
precision
>
=
0
)
{
*
format_ptr
++
=
'.'
;
*
format_ptr
++
=
'.'
;
*
format_ptr
++
=
'*'
;
*
format_ptr
++
=
'*'
;
}
}
...
@@ -1149,7 +1149,7 @@ int snprintf_float(T value, int precision, float_spec spec, buffer<char>& buf) {
...
@@ -1149,7 +1149,7 @@ int snprintf_float(T value, int precision, float_spec spec, buffer<char>& buf) {
#endif
#endif
// Suppress the warning about a nonliteral format string.
// Suppress the warning about a nonliteral format string.
auto
snprintf_ptr
=
FMT_SNPRINTF
;
auto
snprintf_ptr
=
FMT_SNPRINTF
;
int
result
=
precision
>
0
int
result
=
precision
>
=
0
?
snprintf_ptr
(
begin
,
capacity
,
format
,
precision
,
value
)
?
snprintf_ptr
(
begin
,
capacity
,
format
,
precision
,
value
)
:
snprintf_ptr
(
begin
,
capacity
,
format
,
value
);
:
snprintf_ptr
(
begin
,
capacity
,
format
,
value
);
if
(
result
<
0
)
{
if
(
result
<
0
)
{
...
@@ -1164,6 +1164,10 @@ int snprintf_float(T value, int precision, float_spec spec, buffer<char>& buf) {
...
@@ -1164,6 +1164,10 @@ int snprintf_float(T value, int precision, float_spec spec, buffer<char>& buf) {
}
}
auto
is_digit
=
[](
char
c
)
{
return
c
>=
'0'
&&
c
<=
'9'
;
};
auto
is_digit
=
[](
char
c
)
{
return
c
>=
'0'
&&
c
<=
'9'
;
};
if
(
spec
.
format
==
float_format
::
fixed
)
{
if
(
spec
.
format
==
float_format
::
fixed
)
{
if
(
precision
==
0
)
{
buf
.
resize
(
size
);
return
0
;
}
// Find and remove the decimal point.
// Find and remove the decimal point.
auto
end
=
begin
+
size
,
p
=
end
;
auto
end
=
begin
+
size
,
p
=
end
;
do
{
do
{
...
...
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