diff options
author | Eric Haszlakiewicz <erh+git@nimenees.com> | 2020-05-16 01:29:18 +0000 |
---|---|---|
committer | Eric Haszlakiewicz <erh+git@nimenees.com> | 2020-05-16 01:29:18 +0000 |
commit | 0a3d22b9bb58dfbba8b0ab25b9fb14fdf6136f49 (patch) | |
tree | fcc1012f3353f7400c16a4814d72953cb16f79d5 | |
parent | 1526c84a13fa3c5408e2eaa3658fd1a0137673fb (diff) | |
download | json-c-0a3d22b9bb58dfbba8b0ab25b9fb14fdf6136f49.tar.gz |
Revert part of PR#606 and use isnan/isinf again, but provide macro implementations of those in math_compat.h is needed, as it seems to be on AIX and IBM i systems.
-rw-r--r-- | json_object.c | 7 | ||||
-rw-r--r-- | math_compat.h | 7 |
2 files changed, 8 insertions, 6 deletions
diff --git a/json_object.c b/json_object.c index 527cd31..04164d0 100644 --- a/json_object.c +++ b/json_object.c @@ -903,15 +903,11 @@ static int json_object_double_to_json_string_format(struct json_object *jso, str * ECMA 262 section 9.8.1 defines * how to handle these cases as strings */ -#ifdef HAVE_DECL_ISNAN if (isnan(jso->o.c_double)) { size = snprintf(buf, sizeof(buf), "NaN"); } - else -#endif -#ifdef HAVE_DECL_ISINF - if (isinf(jso->o.c_double)) + else if (isinf(jso->o.c_double)) { if (jso->o.c_double > 0) size = snprintf(buf, sizeof(buf), "Infinity"); @@ -919,7 +915,6 @@ static int json_object_double_to_json_string_format(struct json_object *jso, str size = snprintf(buf, sizeof(buf), "-Infinity"); } else -#endif { const char *std_format = "%.17g"; int format_drops_decimals = 0; diff --git a/math_compat.h b/math_compat.h index fdbad4d..2382fe1 100644 --- a/math_compat.h +++ b/math_compat.h @@ -12,6 +12,9 @@ #ifdef HAVE_DECL__ISNAN #include <float.h> #define isnan(x) _isnan(x) +#else +/* On platforms like AIX and "IBM i" we need to provide our own isnan */ +#define isnan(x) ((x) != (x)) #endif #endif @@ -19,6 +22,10 @@ #ifdef HAVE_DECL__FINITE #include <float.h> #define isinf(x) (!_finite(x)) +#else +#include <float.h> +/* On platforms like AIX and "IBM i" we need to provide our own isinf */ +#define isinf(x) ((x) < -DBL_MAX || (x) > DBL_MAX) #endif #endif |