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