Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
yaml-cpp
Commits
895af262
Commit
895af262
authored
Apr 13, 2013
by
Jesse Beder
Browse files
Fix floating point precision on input.
parent
ae42def6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
0 deletions
+10
-0
include/yaml-cpp/node/convert.h
include/yaml-cpp/node/convert.h
+1
-0
test/new-api/nodetests.cpp
test/new-api/nodetests.cpp
+9
-0
No files found.
include/yaml-cpp/node/convert.h
View file @
895af262
...
...
@@ -78,6 +78,7 @@ namespace YAML
struct convert<type> {\
static Node encode(const type& rhs) {\
std::stringstream stream;\
stream.precision(std::numeric_limits<type>::digits10 + 1);\
stream << rhs;\
return Node(stream.str());\
}\
...
...
test/new-api/nodetests.cpp
View file @
895af262
...
...
@@ -498,6 +498,14 @@ namespace Test
YAML_ASSERT_THROWS
(
node
.
begin
()
->
begin
()
->
IsDefined
(),
YAML
::
InvalidNode
);
return
true
;
}
TEST
FloatingPrecision
()
{
const
double
x
=
0.123456789
;
YAML
::
Node
node
=
YAML
::
Node
(
x
);
YAML_ASSERT
(
node
.
as
<
double
>
()
==
x
);
return
true
;
}
}
void
RunNodeTest
(
TEST
(
*
test
)(),
const
std
::
string
&
name
,
int
&
passed
,
int
&
total
)
{
...
...
@@ -560,6 +568,7 @@ namespace Test
RunNodeTest
(
&
Node
::
ForceInsertIntoMap
,
"force insert into map"
,
passed
,
total
);
RunNodeTest
(
&
Node
::
ResetNode
,
"reset node"
,
passed
,
total
);
RunNodeTest
(
&
Node
::
DereferenceIteratorError
,
"dereference iterator error"
,
passed
,
total
);
RunNodeTest
(
&
Node
::
FloatingPrecision
,
"floating precision"
,
passed
,
total
);
std
::
cout
<<
"Node tests: "
<<
passed
<<
"/"
<<
total
<<
" passed
\n
"
;
return
passed
==
total
;
...
...
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