summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Feit <mfeit@internet2.edu>2019-03-14 15:07:35 -0400
committerNicolas Williams <nico@cryptonector.com>2019-04-07 14:33:36 -0500
commitad9fc9f559e78a764aac20f669f23cdd020cd943 (patch)
tree67c22dd072ef8bce539cd10ef9536213711ffefb
parent263e1061ea03a10ba280ef820adf537ffd71f3c0 (diff)
Improve jv_is_integer()
-rw-r--r--src/jv.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/jv.c b/src/jv.c
index 2427b009..2f87bab5 100644
--- a/src/jv.c
+++ b/src/jv.c
@@ -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;
}
/*