Skip to content

Commit

Permalink
Improve jv_is_integer()
Browse files Browse the repository at this point in the history
  • Loading branch information
mfeit-internet2 authored and nicowilliams committed Apr 7, 2019
1 parent 263e106 commit ad9fc9f
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/jv.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <stdarg.h>
#include <limits.h>
#include <math.h>
#include <float.h>

#include "jv_alloc.h"
#include "jv.h"
Expand Down Expand Up @@ -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;
}

/*
Expand Down

0 comments on commit ad9fc9f

Please sign in to comment.