mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2025-06-08 17:30:13 +02:00
Merge pull request #21 from hiharin/master
Hmmm. Not ideal. A round-trip should reproduce the original, but null -> NaN -> ? But I guess it's no worse than it was. The different behavior for Win CE is troubling, but it only affects people who are using these extreme values. I've worked with Inf/NaN before, so I understand your pain.
This commit is contained in:
commit
1a6426ac19
@ -13,6 +13,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
#if defined(_MSC_VER) && _MSC_VER >= 1400 // VC++ 8.0
|
#if defined(_MSC_VER) && _MSC_VER >= 1400 // VC++ 8.0
|
||||||
// Disable warning about strdup being deprecated.
|
// Disable warning about strdup being deprecated.
|
||||||
@ -79,7 +80,29 @@ std::string valueToString(double value) {
|
|||||||
sprintf_s(buffer, sizeof(buffer), "%.16g", value);
|
sprintf_s(buffer, sizeof(buffer), "%.16g", value);
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
|
if ( isfinite( value ))
|
||||||
|
{
|
||||||
snprintf(buffer, sizeof(buffer), "%.16g", value);
|
snprintf(buffer, sizeof(buffer), "%.16g", value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// IEEE standard states that NaN values will not compare to themselves
|
||||||
|
if ( value != value)
|
||||||
|
{
|
||||||
|
snprintf(buffer, sizeof(buffer), "null");
|
||||||
|
}
|
||||||
|
else if ( value < 0)
|
||||||
|
{
|
||||||
|
snprintf(buffer, sizeof(buffer), "-1e+9999");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
snprintf(buffer, sizeof(buffer), "1e+9999");
|
||||||
|
}
|
||||||
|
// nothing more to do, return.
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
fixNumericLocale(buffer, buffer + strlen(buffer));
|
fixNumericLocale(buffer, buffer + strlen(buffer));
|
||||||
return buffer;
|
return buffer;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user