diff options
author | Mark Feit <mfeit@internet2.edu> | 2019-03-14 15:07:35 -0400 |
---|---|---|
committer | Nicolas Williams <nico@cryptonector.com> | 2019-04-07 14:33:36 -0500 |
commit | ad9fc9f559e78a764aac20f669f23cdd020cd943 (patch) | |
tree | 67c22dd072ef8bce539cd10ef9536213711ffefb /src | |
parent | 263e1061ea03a10ba280ef820adf537ffd71f3c0 (diff) |
Improve jv_is_integer()
Diffstat (limited to 'src')
-rw-r--r-- | src/jv.c | 9 |
1 files changed, 5 insertions, 4 deletions
@@ -7,6 +7,7 @@ #include <stdarg.h> #include <limits.h> #include <math.h> +#include <float.h> #include "jv_alloc.h" #include "jv.h" @@ -152,11 +153,11 @@ int jv_is_integer(jv j){ return 0; } double x = jv_number_value(j); - if(x != x || x > INT_MAX || x < INT_MIN){ - return 0; - } - return x == (int)x; + double ipart; + double fpart = modf(x, &ipart); + + return fabs(fpart) < DBL_EPSILON; } /* |