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
ca0dcce2
Commit
ca0dcce2
authored
Jul 24, 2014
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CountDigits -> count_digits
parent
c1db2935
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
8 deletions
+8
-8
format.h
format.h
+8
-8
No files found.
format.h
View file @
ca0dcce2
...
...
@@ -432,23 +432,23 @@ extern const uint64_t POWERS_OF_10_64[];
#if FMT_GCC_VERSION >= 400 || FMT_HAS_BUILTIN(__builtin_clzll)
// Returns the number of decimal digits in n. Leading zeros are not counted
// except for n == 0 in which case
CountD
igits returns 1.
inline
unsigned
CountD
igits
(
uint64_t
n
)
{
// except for n == 0 in which case
count_d
igits returns 1.
inline
unsigned
count_d
igits
(
uint64_t
n
)
{
// Based on http://graphics.stanford.edu/~seander/bithacks.html#IntegerLog10
// and the benchmark https://github.com/localvoid/cxx-benchmark-count-digits.
uint64_t
t
=
(
64
-
__builtin_clzll
(
n
|
1
))
*
1233
>>
12
;
return
t
-
(
n
<
POWERS_OF_10_64
[
t
])
+
1
;
}
# if FMT_GCC_VERSION >= 400 || FMT_HAS_BUILTIN(__builtin_clz)
// Optional version of
CountD
igits for better performance on 32-bit platforms.
inline
unsigned
CountD
igits
(
uint32_t
n
)
{
// Optional version of
count_d
igits for better performance on 32-bit platforms.
inline
unsigned
count_d
igits
(
uint32_t
n
)
{
uint32_t
t
=
(
32
-
__builtin_clz
(
n
|
1
))
*
1233
>>
12
;
return
t
-
(
n
<
POWERS_OF_10_32
[
t
])
+
1
;
}
# endif
#else
// Slower version of
CountD
igits used when __builtin_clz is not available.
inline
unsigned
CountD
igits
(
uint64_t
n
)
{
// Slower version of
count_d
igits used when __builtin_clz is not available.
inline
unsigned
count_d
igits
(
uint64_t
n
)
{
unsigned
count
=
1
;
for
(;;)
{
// Integer division is slow so do it for a group of four digits instead
...
...
@@ -1622,7 +1622,7 @@ void BasicWriter<Char>::write_int(T value, const Spec &spec) {
}
switch
(
spec
.
type
())
{
case
0
:
case
'd'
:
{
unsigned
num_digits
=
internal
::
CountD
igits
(
abs_value
);
unsigned
num_digits
=
internal
::
count_d
igits
(
abs_value
);
CharPtr
p
=
PrepareBufferForInt
(
num_digits
,
spec
,
prefix
,
prefix_size
)
+
1
-
num_digits
;
internal
::
FormatDecimal
(
GetBase
(
p
),
abs_value
,
num_digits
);
...
...
@@ -1915,7 +1915,7 @@ inline void FormatDec(char *&buffer, T value) {
*
buffer
++
=
internal
::
DIGITS
[
index
+
1
];
return
;
}
unsigned
num_digits
=
internal
::
CountD
igits
(
abs_value
);
unsigned
num_digits
=
internal
::
count_d
igits
(
abs_value
);
internal
::
FormatDecimal
(
buffer
,
abs_value
,
num_digits
);
buffer
+=
num_digits
;
}
...
...
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