Skip to content

Commit

Permalink
Revert part of PR#606 and use isnan/isinf again, but provide macro im…
Browse files Browse the repository at this point in the history
…plementations of those in math_compat.h is needed, as it seems to be on AIX and IBM i systems.
  • Loading branch information
hawicz committed May 16, 2020
1 parent 1526c84 commit 0a3d22b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 1 addition & 6 deletions json_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -903,23 +903,18 @@ 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");
else
size = snprintf(buf, sizeof(buf), "-Infinity");
}
else
#endif
{
const char *std_format = "%.17g";
int format_drops_decimals = 0;
Expand Down
7 changes: 7 additions & 0 deletions math_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,20 @@
#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

#ifndef HAVE_DECL_ISINF
#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

Expand Down

0 comments on commit 0a3d22b

Please sign in to comment.