From 91c88a4ec7e6d0b1ed675d132033efebd1b1d2c4 Mon Sep 17 00:00:00 2001 From: Kevin Larke Date: Fri, 22 May 2015 13:56:02 -0700 Subject: [PATCH] cmMath.h/c : Added cmIsCloseX(). --- cmMath.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ cmMath.h | 7 +++++++ 2 files changed, 55 insertions(+) diff --git a/cmMath.c b/cmMath.c index 2ac7a82..028354e 100644 --- a/cmMath.c +++ b/cmMath.c @@ -419,3 +419,51 @@ double cmRandDouble( double min, double max ) double offs = max - min; return min + cmMax(0,cmMin(offs,(offs * (double)rand() / RAND_MAX))); } + + +//================================================================= +// Base on: http://stackoverflow.com/questions/3874627/floating-point-comparison-functions-for-c-sharp + +bool cmIsCloseD( double x0, double x1, double eps ) +{ + double d = fabs(x0-x1); + + if( x0 == x1 ) + return true; + + if( x0==0 || x1==0 || d