w.deng | e87b500 | 2025-08-20 10:43:03 +0800 | [diff] [blame] | 1 | #ifndef __math_compat_h |
| 2 | #define __math_compat_h |
| 3 | |
| 4 | /** |
| 5 | * @file |
| 6 | * @brief Do not use, json-c internal, may be changed or removed at any time. |
| 7 | */ |
| 8 | |
| 9 | /* Define isnan, isinf, infinity and nan on Windows/MSVC */ |
| 10 | |
| 11 | #ifndef HAVE_DECL_ISNAN |
| 12 | #ifdef HAVE_DECL__ISNAN |
| 13 | #include <float.h> |
| 14 | #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)) |
| 18 | #endif |
| 19 | #endif |
| 20 | |
| 21 | #ifndef HAVE_DECL_ISINF |
| 22 | #ifdef HAVE_DECL__FINITE |
| 23 | #include <float.h> |
| 24 | #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) |
| 29 | #endif |
| 30 | #endif |
| 31 | |
| 32 | #ifndef HAVE_DECL_INFINITY |
| 33 | #include <float.h> |
| 34 | #define INFINITY (DBL_MAX + DBL_MAX) |
| 35 | #define HAVE_DECL_INFINITY |
| 36 | #endif |
| 37 | |
| 38 | #ifndef HAVE_DECL_NAN |
| 39 | #define NAN (INFINITY - INFINITY) |
| 40 | #define HAVE_DECL_NAN |
| 41 | #endif |
| 42 | |
| 43 | #endif |