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
835b86d9
Commit
835b86d9
authored
Jul 10, 2011
by
Jesse Beder
Browse files
Fixed negative infinity parsing
parent
94dc63af
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
9 deletions
+16
-9
include/yaml-cpp/conversion.h
include/yaml-cpp/conversion.h
+13
-6
test/parsertests.cpp
test/parsertests.cpp
+3
-3
No files found.
include/yaml-cpp/conversion.h
View file @
835b86d9
...
...
@@ -23,9 +23,11 @@ namespace YAML
YAML_CPP_API
bool
Convert
(
const
std
::
string
&
input
,
_Null
&
output
);
inline
bool
IsInfinity
(
const
std
::
string
&
input
)
{
return
input
==
".inf"
||
input
==
".Inf"
||
input
==
".INF"
||
input
==
"+.inf"
||
input
==
"+.Inf"
||
input
==
"+.INF"
||
input
==
"-.inf"
||
input
==
"-.Inf"
||
input
==
"-.INF"
;
return
input
==
".inf"
||
input
==
".Inf"
||
input
==
".INF"
||
input
==
"+.inf"
||
input
==
"+.Inf"
||
input
==
"+.INF"
;
}
inline
bool
IsNegativeInfinity
(
const
std
::
string
&
input
)
{
return
input
==
"-.inf"
||
input
==
"-.Inf"
||
input
==
"-.INF"
;
}
inline
bool
IsNaN
(
const
std
::
string
&
input
)
{
...
...
@@ -41,9 +43,14 @@ namespace YAML
if
(
!!
stream
)
return
true
;
if
(
std
::
numeric_limits
<
T
>::
has_infinity
&&
IsInfinity
(
input
))
{
output
=
std
::
numeric_limits
<
T
>::
infinity
();
return
true
;
if
(
std
::
numeric_limits
<
T
>::
has_infinity
)
{
if
(
IsInfinity
(
input
))
{
output
=
std
::
numeric_limits
<
T
>::
infinity
();
return
true
;
}
else
if
(
IsNegativeInfinity
(
input
))
{
output
=
-
std
::
numeric_limits
<
T
>::
infinity
();
return
true
;
}
}
if
(
std
::
numeric_limits
<
T
>::
has_quiet_NaN
&&
IsNaN
(
input
))
{
...
...
test/parsertests.cpp
View file @
835b86d9
...
...
@@ -822,13 +822,13 @@ namespace Test
parser
.
GetNextDocument
(
doc
);
for
(
unsigned
i
=
0
;
i
<
doc
.
size
();
i
++
)
if
(
doc
[
i
].
to
<
double
>
()
!=
std
::
numeric_limits
<
double
>::
infinity
())
if
(
doc
[
i
].
to
<
double
>
()
!=
(
i
<
6
?
+
1
:
-
1
)
*
std
::
numeric_limits
<
double
>::
infinity
())
return
false
;
for
(
unsigned
i
=
0
;
i
<
doc
.
size
();
i
++
)
if
(
doc
[
i
].
to
<
long
double
>
()
!=
std
::
numeric_limits
<
long
double
>::
infinity
())
if
(
doc
[
i
].
to
<
long
double
>
()
!=
(
i
<
6
?
+
1
:
-
1
)
*
std
::
numeric_limits
<
long
double
>::
infinity
())
return
false
;
for
(
unsigned
i
=
0
;
i
<
doc
.
size
();
i
++
)
if
(
doc
[
i
].
to
<
float
>
()
!=
std
::
numeric_limits
<
float
>::
infinity
())
if
(
doc
[
i
].
to
<
float
>
()
!=
(
i
<
6
?
+
1
:
-
1
)
*
std
::
numeric_limits
<
float
>::
infinity
())
return
false
;
return
true
;
}
...
...
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