From c06d8264d010186c3ac98fd1eaccf9b2ba735728 Mon Sep 17 00:00:00 2001 From: Alanscut Date: Fri, 6 Dec 2019 18:16:27 +0800 Subject: [PATCH] improve compare_double function --- cJSON.c | 2 +- cJSON.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cJSON.c b/cJSON.c index 77ca7d3..e71d22f 100644 --- a/cJSON.c +++ b/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. */ diff --git a/cJSON.h b/cJSON.h index b896151..2c53562 100644 --- a/cJSON.h +++ b/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 */