Skip to content

Commit 0a3d22b

Browse files
committed
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.
1 parent 1526c84 commit 0a3d22b

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

json_object.c

+1-6
Original file line numberDiff line numberDiff line change
@@ -903,23 +903,18 @@ static int json_object_double_to_json_string_format(struct json_object *jso, str
903903
* ECMA 262 section 9.8.1 defines
904904
* how to handle these cases as strings
905905
*/
906-
#ifdef HAVE_DECL_ISNAN
907906
if (isnan(jso->o.c_double))
908907
{
909908
size = snprintf(buf, sizeof(buf), "NaN");
910909
}
911-
else
912-
#endif
913-
#ifdef HAVE_DECL_ISINF
914-
if (isinf(jso->o.c_double))
910+
else if (isinf(jso->o.c_double))
915911
{
916912
if (jso->o.c_double > 0)
917913
size = snprintf(buf, sizeof(buf), "Infinity");
918914
else
919915
size = snprintf(buf, sizeof(buf), "-Infinity");
920916
}
921917
else
922-
#endif
923918
{
924919
const char *std_format = "%.17g";
925920
int format_drops_decimals = 0;

math_compat.h

+7
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,20 @@
1212
#ifdef HAVE_DECL__ISNAN
1313
#include <float.h>
1414
#define isnan(x) _isnan(x)
15+
#else
16+
/* On platforms like AIX and "IBM i" we need to provide our own isnan */
17+
#define isnan(x) ((x) != (x))
1518
#endif
1619
#endif
1720

1821
#ifndef HAVE_DECL_ISINF
1922
#ifdef HAVE_DECL__FINITE
2023
#include <float.h>
2124
#define isinf(x) (!_finite(x))
25+
#else
26+
#include <float.h>
27+
/* On platforms like AIX and "IBM i" we need to provide our own isinf */
28+
#define isinf(x) ((x) < -DBL_MAX || (x) > DBL_MAX)
2229
#endif
2330
#endif
2431

0 commit comments

Comments
 (0)