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
0497875f
Commit
0497875f
authored
Dec 05, 2018
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Stop the orgy of casts
parent
37dc495b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
8 deletions
+7
-8
include/fmt/format-inl.h
include/fmt/format-inl.h
+7
-8
No files found.
include/fmt/format-inl.h
View file @
0497875f
...
...
@@ -539,7 +539,7 @@ FMT_FUNC bool grisu2_gen_digits(
#endif
struct
gen_digits_params
{
unsigned
num_digits
;
int
num_digits
;
bool
fixed
;
bool
upper
;
bool
trailing_zeros
;
...
...
@@ -617,11 +617,11 @@ struct fill {
// The number is given as v = f * pow(10, exp), where f has size digits.
template
<
typename
Handler
>
FMT_FUNC
void
grisu2_prettify
(
const
gen_digits_params
&
params
,
ptrdiff_
t
size
,
int
exp
,
Handler
&&
handler
)
{
in
t
size
,
int
exp
,
Handler
&&
handler
)
{
if
(
!
params
.
fixed
)
{
// Insert a decimal point after the first digit and add an exponent.
handler
.
insert
(
1
,
'.'
);
exp
+=
s
tatic_cast
<
int
>
(
size
)
-
1
;
exp
+=
s
ize
-
1
;
if
(
size
<
params
.
num_digits
)
handler
.
append
(
params
.
num_digits
-
size
,
'0'
);
handler
.
append
(
params
.
upper
?
'E'
:
'e'
);
...
...
@@ -629,13 +629,12 @@ FMT_FUNC void grisu2_prettify(const gen_digits_params ¶ms,
return
;
}
// pow(10, full_exp - 1) <= v <= pow(10, full_exp).
int
int_size
=
static_cast
<
int
>
(
size
);
int
full_exp
=
int_size
+
exp
;
int
full_exp
=
size
+
exp
;
const
int
exp_threshold
=
21
;
if
(
int_
size
<=
full_exp
&&
full_exp
<=
exp_threshold
)
{
if
(
size
<=
full_exp
&&
full_exp
<=
exp_threshold
)
{
// 1234e7 -> 12340000000[.0+]
handler
.
append
(
full_exp
-
int_
size
,
'0'
);
int
num_zeros
=
static_cast
<
int
>
(
params
.
num_digits
)
-
full_exp
;
handler
.
append
(
full_exp
-
size
,
'0'
);
int
num_zeros
=
params
.
num_digits
-
full_exp
;
if
(
num_zeros
>
0
&&
params
.
trailing_zeros
)
{
handler
.
append
(
'.'
);
handler
.
append
(
num_zeros
,
'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