Explorar el Código

improve compare_double function

Alanscut hace 5 años
padre
commit
c06d8264d0
Se han modificado 2 ficheros con 3 adiciones y 3 borrados
  1. 1 1
      cJSON.c
  2. 2 2
      cJSON.h

+ 1 - 1
cJSON.c

@@ -483,7 +483,7 @@ static void update_offset(printbuffer * const buffer)
 /* securely comparison of floating-point variables */
 static cJSON_bool compare_double(double a, double b)
 {
-    return (fabs(a - b) <= a * CJSON_DOUBLE_PRECIION);
+    return (fabs(a - b) <= CJSON_DOUBLE_PRECISION);
 }
 
 /* Render the number nicely from the given item into a string. */

+ 2 - 2
cJSON.h

@@ -138,8 +138,8 @@ typedef int cJSON_bool;
 #endif
 
 /* Precision of double variables comparison */
-#ifndef CJSON_DOUBLE_PRECIION
-#define CJSON_DOUBLE_PRECIION .00001
+#ifndef CJSON_DOUBLE_PRECISION
+#define CJSON_DOUBLE_PRECISION .0000000000000001
 #endif
 
 /* returns the version of cJSON as a string */