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
4f2ee892
Commit
4f2ee892
authored
Sep 11, 2020
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use built-in FP formatter for any precision
parent
efe3694f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
5 additions
and
7 deletions
+5
-7
include/fmt/format-inl.h
include/fmt/format-inl.h
+4
-6
test/format-impl-test.cc
test/format-impl-test.cc
+1
-1
No files found.
include/fmt/format-inl.h
View file @
4f2ee892
...
@@ -864,8 +864,7 @@ FMT_ALWAYS_INLINE digits::result grisu_gen_digits(fp value, uint64_t error,
...
@@ -864,8 +864,7 @@ FMT_ALWAYS_INLINE digits::result grisu_gen_digits(fp value, uint64_t error,
FMT_ASSERT
(
false
,
"invalid number of digits"
);
FMT_ASSERT
(
false
,
"invalid number of digits"
);
}
}
--
exp
;
--
exp
;
uint64_t
remainder
=
auto
remainder
=
(
static_cast
<
uint64_t
>
(
integral
)
<<
-
one
.
e
)
+
fractional
;
(
static_cast
<
uint64_t
>
(
integral
)
<<
-
one
.
e
)
+
fractional
;
result
=
handler
.
on_digit
(
static_cast
<
char
>
(
'0'
+
digit
),
result
=
handler
.
on_digit
(
static_cast
<
char
>
(
'0'
+
digit
),
data
::
powers_of_10_64
[
exp
]
<<
-
one
.
e
,
remainder
,
data
::
powers_of_10_64
[
exp
]
<<
-
one
.
e
,
remainder
,
error
,
exp
,
true
);
error
,
exp
,
true
);
...
@@ -875,8 +874,7 @@ FMT_ALWAYS_INLINE digits::result grisu_gen_digits(fp value, uint64_t error,
...
@@ -875,8 +874,7 @@ FMT_ALWAYS_INLINE digits::result grisu_gen_digits(fp value, uint64_t error,
for
(;;)
{
for
(;;)
{
fractional
*=
10
;
fractional
*=
10
;
error
*=
10
;
error
*=
10
;
char
digit
=
char
digit
=
static_cast
<
char
>
(
'0'
+
(
fractional
>>
-
one
.
e
));
static_cast
<
char
>
(
'0'
+
static_cast
<
char
>
(
fractional
>>
-
one
.
e
));
fractional
&=
one
.
f
-
1
;
fractional
&=
one
.
f
-
1
;
--
exp
;
--
exp
;
result
=
handler
.
on_digit
(
digit
,
one
.
f
,
fractional
,
error
,
exp
,
false
);
result
=
handler
.
on_digit
(
digit
,
one
.
f
,
fractional
,
error
,
exp
,
false
);
...
@@ -913,6 +911,7 @@ struct fixed_handler {
...
@@ -913,6 +911,7 @@ struct fixed_handler {
uint64_t
error
,
int
,
bool
integral
)
{
uint64_t
error
,
int
,
bool
integral
)
{
FMT_ASSERT
(
remainder
<
divisor
,
""
);
FMT_ASSERT
(
remainder
<
divisor
,
""
);
buf
[
size
++
]
=
digit
;
buf
[
size
++
]
=
digit
;
if
(
!
integral
&&
error
>=
remainder
)
return
digits
::
error
;
if
(
size
<
precision
)
return
digits
::
more
;
if
(
size
<
precision
)
return
digits
::
more
;
if
(
!
integral
)
{
if
(
!
integral
)
{
// Check if error * 2 < divisor with overflow prevention.
// Check if error * 2 < divisor with overflow prevention.
...
@@ -1152,7 +1151,6 @@ int format_float(T value, int precision, float_specs specs, buffer<char>& buf) {
...
@@ -1152,7 +1151,6 @@ int format_float(T value, int precision, float_specs specs, buffer<char>& buf) {
}
}
buf
.
try_resize
(
to_unsigned
(
handler
.
size
));
buf
.
try_resize
(
to_unsigned
(
handler
.
size
));
}
else
{
}
else
{
if
(
precision
>
17
)
return
snprintf_float
(
value
,
precision
,
specs
,
buf
);
fp
normalized
=
normalize
(
fp
(
value
));
fp
normalized
=
normalize
(
fp
(
value
));
const
auto
cached_pow
=
get_cached_power
(
const
auto
cached_pow
=
get_cached_power
(
min_exp
-
(
normalized
.
e
+
fp
::
significand_size
),
cached_exp10
);
min_exp
-
(
normalized
.
e
+
fp
::
significand_size
),
cached_exp10
);
...
@@ -1160,7 +1158,7 @@ int format_float(T value, int precision, float_specs specs, buffer<char>& buf) {
...
@@ -1160,7 +1158,7 @@ int format_float(T value, int precision, float_specs specs, buffer<char>& buf) {
fixed_handler
handler
{
buf
.
data
(),
0
,
precision
,
-
cached_exp10
,
fixed
};
fixed_handler
handler
{
buf
.
data
(),
0
,
precision
,
-
cached_exp10
,
fixed
};
if
(
grisu_gen_digits
(
normalized
,
1
,
exp
,
handler
)
==
digits
::
error
)
{
if
(
grisu_gen_digits
(
normalized
,
1
,
exp
,
handler
)
==
digits
::
error
)
{
exp
+=
handler
.
size
-
cached_exp10
-
1
;
exp
+=
handler
.
size
-
cached_exp10
-
1
;
fallback_format
(
value
,
handler
.
size
,
buf
,
exp
);
fallback_format
(
value
,
handler
.
precision
,
buf
,
exp
);
return
exp
;
return
exp
;
}
}
int
num_digits
=
handler
.
size
;
int
num_digits
=
handler
.
size
;
...
...
test/format-impl-test.cc
View file @
4f2ee892
...
@@ -307,7 +307,7 @@ TEST(FPTest, FixedHandler) {
...
@@ -307,7 +307,7 @@ TEST(FPTest, FixedHandler) {
EXPECT_THROW
(
handler
().
on_digit
(
'0'
,
100
,
100
,
0
,
exp
,
false
),
EXPECT_THROW
(
handler
().
on_digit
(
'0'
,
100
,
100
,
0
,
exp
,
false
),
assertion_failure
);
assertion_failure
);
namespace
digits
=
fmt
::
detail
::
digits
;
namespace
digits
=
fmt
::
detail
::
digits
;
EXPECT_EQ
(
handler
(
1
).
on_digit
(
'0'
,
100
,
10
,
10
,
exp
,
false
),
digits
::
done
);
EXPECT_EQ
(
handler
(
1
).
on_digit
(
'0'
,
100
,
10
,
10
,
exp
,
false
),
digits
::
error
);
// Check that divisor - error doesn't overflow.
// Check that divisor - error doesn't overflow.
EXPECT_EQ
(
handler
(
1
).
on_digit
(
'0'
,
100
,
10
,
101
,
exp
,
false
),
digits
::
error
);
EXPECT_EQ
(
handler
(
1
).
on_digit
(
'0'
,
100
,
10
,
101
,
exp
,
false
),
digits
::
error
);
// Check that 2 * error doesn't overflow.
// Check that 2 * error doesn't overflow.
...
...
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