Skip to content

Commit

Permalink
Changed PropVal to map between NONE and Nan for asDouble() and toJSON()
Browse files Browse the repository at this point in the history
  • Loading branch information
oschulz committed Apr 24, 2015
1 parent 87be07b commit 7b434cb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Props.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,11 @@ void PropVal::substVars(const Props &varValues, bool useEnvVars, bool ignoreMiss


void PropVal::toJSON(std::ostream &out, Real x) {
out.precision(16);
out << x;
if (x != x) toJSON(out, nullptr); // NaN
else {
out.precision(16);
out << x;
}
}


Expand Down
3 changes: 3 additions & 0 deletions src/Props.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <algorithm>
#include <functional>
#include <iosfwd>
#include <limits>
#include <cassert>

#include "Name.h"
Expand Down Expand Up @@ -381,6 +382,8 @@ class PropVal final: public virtual Printable {

double asDouble() const {
switch (m_type) {
case Type::NONE:
return std::numeric_limits<double>::quiet_NaN();
case Type::INTEGER:
return m_content.i;
case Type::REAL:
Expand Down

0 comments on commit 7b434cb

Please sign in to comment.