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
0201c8db
Commit
0201c8db
authored
Jan 07, 2020
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Restructure float_format
parent
9e3f3e8c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
20 deletions
+20
-20
include/fmt/format-inl.h
include/fmt/format-inl.h
+20
-20
No files found.
include/fmt/format-inl.h
View file @
0201c8db
...
@@ -457,7 +457,7 @@ inline fp operator*(fp x, fp y) { return {multiply(x.f, y.f), x.e + y.e + 64}; }
...
@@ -457,7 +457,7 @@ inline fp operator*(fp x, fp y) { return {multiply(x.f, y.f), x.e + y.e + 64}; }
// Returns a cached power of 10 `c_k = c_k.f * pow(2, c_k.e)` such that its
// Returns a cached power of 10 `c_k = c_k.f * pow(2, c_k.e)` such that its
// (binary) exponent satisfies `min_exponent <= c_k.e <= min_exponent + 28`.
// (binary) exponent satisfies `min_exponent <= c_k.e <= min_exponent + 28`.
FMT_FUNC
fp
get_cached_power
(
int
min_exponent
,
int
&
pow10_exponent
)
{
inline
fp
get_cached_power
(
int
min_exponent
,
int
&
pow10_exponent
)
{
const
uint64_t
one_over_log2_10
=
0x4d104d42
;
// round(pow(2, 32) / log2(10))
const
uint64_t
one_over_log2_10
=
0x4d104d42
;
// round(pow(2, 32) / log2(10))
int
index
=
static_cast
<
int
>
(
int
index
=
static_cast
<
int
>
(
static_cast
<
int64_t
>
(
static_cast
<
int64_t
>
(
...
@@ -1043,25 +1043,7 @@ int format_float(T value, int precision, float_specs specs, buffer<char>& buf) {
...
@@ -1043,25 +1043,7 @@ int format_float(T value, int precision, float_specs specs, buffer<char>& buf) {
int
exp
=
0
;
int
exp
=
0
;
const
int
min_exp
=
-
60
;
// alpha in Grisu.
const
int
min_exp
=
-
60
;
// alpha in Grisu.
int
cached_exp10
=
0
;
// K in Grisu.
int
cached_exp10
=
0
;
// K in Grisu.
if
(
precision
!=
-
1
)
{
if
(
precision
<
0
)
{
if
(
precision
>
17
)
return
snprintf_float
(
value
,
precision
,
specs
,
buf
);
fp
normalized
=
normalize
(
fp
(
value
));
const
auto
cached_pow
=
get_cached_power
(
min_exp
-
(
normalized
.
e
+
fp
::
significand_size
),
cached_exp10
);
normalized
=
normalized
*
cached_pow
;
fixed_handler
handler
{
buf
.
data
(),
0
,
precision
,
-
cached_exp10
,
fixed
};
if
(
grisu_gen_digits
(
normalized
,
1
,
exp
,
handler
)
==
digits
::
error
)
return
snprintf_float
(
value
,
precision
,
specs
,
buf
);
int
num_digits
=
handler
.
size
;
if
(
!
fixed
)
{
// Remove trailing zeros.
while
(
num_digits
>
0
&&
buf
[
num_digits
-
1
]
==
'0'
)
{
--
num_digits
;
++
exp
;
}
}
buf
.
resize
(
to_unsigned
(
num_digits
));
}
else
{
fp
fp_value
;
fp
fp_value
;
auto
boundaries
=
specs
.
binary32
auto
boundaries
=
specs
.
binary32
?
fp_value
.
assign_float_with_boundaries
(
value
)
?
fp_value
.
assign_float_with_boundaries
(
value
)
...
@@ -1090,6 +1072,24 @@ int format_float(T value, int precision, float_specs specs, buffer<char>& buf) {
...
@@ -1090,6 +1072,24 @@ int format_float(T value, int precision, float_specs specs, buffer<char>& buf) {
return
exp
;
return
exp
;
}
}
buf
.
resize
(
to_unsigned
(
handler
.
size
));
buf
.
resize
(
to_unsigned
(
handler
.
size
));
}
else
{
if
(
precision
>
17
)
return
snprintf_float
(
value
,
precision
,
specs
,
buf
);
fp
normalized
=
normalize
(
fp
(
value
));
const
auto
cached_pow
=
get_cached_power
(
min_exp
-
(
normalized
.
e
+
fp
::
significand_size
),
cached_exp10
);
normalized
=
normalized
*
cached_pow
;
fixed_handler
handler
{
buf
.
data
(),
0
,
precision
,
-
cached_exp10
,
fixed
};
if
(
grisu_gen_digits
(
normalized
,
1
,
exp
,
handler
)
==
digits
::
error
)
return
snprintf_float
(
value
,
precision
,
specs
,
buf
);
int
num_digits
=
handler
.
size
;
if
(
!
fixed
)
{
// Remove trailing zeros.
while
(
num_digits
>
0
&&
buf
[
num_digits
-
1
]
==
'0'
)
{
--
num_digits
;
++
exp
;
}
}
buf
.
resize
(
to_unsigned
(
num_digits
));
}
}
return
exp
-
cached_exp10
;
return
exp
-
cached_exp10
;
}
}
...
...
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