Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yaml-cpp
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
yaml-cpp
Commits
d4e00bd4
Commit
d4e00bd4
authored
Jul 16, 2024
by
Simon Gene Gottlieb
Committed by
Jesse Beder
Nov 07, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: rename fp_to_string to FpToString to match coding style
parent
bd070a7b
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
12 additions
and
12 deletions
+12
-12
include/yaml-cpp/emitter.h
+1
-1
include/yaml-cpp/fp_to_string.h
+10
-10
include/yaml-cpp/node/convert.h
+1
-1
test/fp_to_string_test.cpp
+0
-0
No files found.
include/yaml-cpp/emitter.h
View file @
d4e00bd4
...
...
@@ -181,7 +181,7 @@ inline Emitter& Emitter::WriteStreamable(T value) {
}
if
(
!
special
)
{
stream
<<
fp_to_s
tring
(
value
,
stream
.
precision
());
stream
<<
FpToS
tring
(
value
,
stream
.
precision
());
}
m_stream
<<
stream
.
str
();
...
...
include/yaml-cpp/fp_to_string.h
View file @
d4e00bd4
...
...
@@ -26,13 +26,13 @@ namespace fp_formatting {
*
* Example:
* std::array<char, 20> buffer;
* auto ct =
c
onvertToChars(buffer.begin(), buffer.end(), 23, 3);
* auto ct =
C
onvertToChars(buffer.begin(), buffer.end(), 23, 3);
* assert(ct = 3);
* assert(buffer[0] == '0');
* assert(buffer[1] == '2');
* assert(buffer[2] == '3');
*/
inline
auto
c
onvertToChars
(
char
*
begin
,
char
*
end
,
size_t
value
,
int
width
=
1
)
->
int
{
inline
auto
C
onvertToChars
(
char
*
begin
,
char
*
end
,
size_t
value
,
int
width
=
1
)
->
int
{
assert
(
width
>=
1
);
assert
(
end
>=
begin
);
// end must be after begin
assert
(
end
-
begin
>=
width
);
// Buffer must be large enough
...
...
@@ -62,7 +62,7 @@ inline auto convertToChars(char* begin, char* end, size_t value, int width=1) ->
* converts a value 'v' to a string. Uses dragonbox for formatting.
*/
template
<
typename
T
>
auto
fp_to_s
tring
(
T
v
,
int
precision
=
0
)
->
std
::
string
{
auto
FpToS
tring
(
T
v
,
int
precision
=
0
)
->
std
::
string
{
// assert(precision > 0);
// hardcoded constant, at which exponent should switch to a scientific notation
int
const
lowerExponentThreshold
=
-
5
;
...
...
@@ -81,7 +81,7 @@ auto fp_to_string(T v, int precision = 0) -> std::string {
auto
r
=
jkj
::
dragonbox
::
to_decimal
(
v
);
auto
digits
=
std
::
array
<
char
,
20
>
{};
// max digits of size_t is 20.
auto
digits_ct
=
c
onvertToChars
(
digits
.
data
(),
digits
.
data
()
+
digits
.
size
(),
r
.
significand
);
auto
digits_ct
=
C
onvertToChars
(
digits
.
data
(),
digits
.
data
()
+
digits
.
size
(),
r
.
significand
);
// check if requested precision is lower than
// required digits for exact representation
...
...
@@ -136,7 +136,7 @@ auto fp_to_string(T v, int precision = 0) -> std::string {
*
(
output_ptr
++
)
=
'e'
;
*
(
output_ptr
++
)
=
(
exponent
>=
0
)
?
'+'
:
'-'
;
auto
exp_digits
=
std
::
array
<
char
,
20
>
{};
auto
exp_digits_ct
=
c
onvertToChars
(
exp_digits
.
data
(),
exp_digits
.
data
()
+
exp_digits
.
size
(),
std
::
abs
(
exponent
),
/*.precision=*/
2
);
auto
exp_digits_ct
=
C
onvertToChars
(
exp_digits
.
data
(),
exp_digits
.
data
()
+
exp_digits
.
size
(),
std
::
abs
(
exponent
),
/*.precision=*/
2
);
for
(
int
i
{
0
};
i
<
exp_digits_ct
;
++
i
)
{
*
(
output_ptr
++
)
=
exp_digits
[
i
];
}
...
...
@@ -184,18 +184,18 @@ auto fp_to_string(T v, int precision = 0) -> std::string {
}
}
inline
auto
fp_to_s
tring
(
float
v
,
size_t
precision
=
0
)
->
std
::
string
{
return
detail
::
fp_formatting
::
fp_to_s
tring
(
v
,
precision
);
inline
auto
FpToS
tring
(
float
v
,
size_t
precision
=
0
)
->
std
::
string
{
return
detail
::
fp_formatting
::
FpToS
tring
(
v
,
precision
);
}
inline
auto
fp_to_s
tring
(
double
v
,
size_t
precision
=
0
)
->
std
::
string
{
return
detail
::
fp_formatting
::
fp_to_s
tring
(
v
,
precision
);
inline
auto
FpToS
tring
(
double
v
,
size_t
precision
=
0
)
->
std
::
string
{
return
detail
::
fp_formatting
::
FpToS
tring
(
v
,
precision
);
}
/**
* dragonbox only works for floats/doubles not long double
*/
inline
auto
fp_to_s
tring
(
long
double
v
,
size_t
precision
=
std
::
numeric_limits
<
long
double
>::
max_digits10
)
->
std
::
string
{
inline
auto
FpToS
tring
(
long
double
v
,
size_t
precision
=
std
::
numeric_limits
<
long
double
>::
max_digits10
)
->
std
::
string
{
std
::
stringstream
ss
;
ss
.
precision
(
precision
);
ss
.
imbue
(
std
::
locale
(
"C"
));
...
...
include/yaml-cpp/node/convert.h
View file @
d4e00bd4
...
...
@@ -130,7 +130,7 @@ inner_encode(const T& rhs, std::stringstream& stream){
stream
<<
".inf"
;
}
}
else
{
stream
<<
fp_to_s
tring
(
rhs
,
stream
.
precision
());
stream
<<
FpToS
tring
(
rhs
,
stream
.
precision
());
}
}
...
...
test/fp_to_string_test.cpp
View file @
d4e00bd4
This diff is collapsed.
Click to expand it.
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