From b6a30dcdd3225e67e7eed7ead68c919c36243ffc Mon Sep 17 00:00:00 2001 From: Robert Helling Date: Wed, 22 Jan 2014 09:04:04 +0100 Subject: Improve floating point equality test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This allows for a relative error rather than an absolute (which would set an artificial scale). This basically says “we trust our data (which comes from the dive computer’s measurement after all) to a certain number of significant digits” rather than “we will never encounter anything smaller than 1 / a million but not zero” which would be awfully unit dependent. Signed-off-by: Robert C. Helling Signed-off-by: Dirk Hohndel --- dive.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dive.h b/dive.h index c56d569ad..408bb99c5 100644 --- a/dive.h +++ b/dive.h @@ -20,7 +20,7 @@ (void) (&_max1 == &_max2); \ _max1 > _max2 ? _max1 : _max2; }) -#define IS_FP_SAME(_a,_b) (abs((_a) - (_b)) < 0.000001) +#define IS_FP_SAME(_a,_b) (abs((_a) - (_b)) < 0.000001 * MAX(abs(_a), abs(_b))) #include #include -- cgit v1.2.3-70-g09d2