1#ifndef Cpl_Math_real_h_
2#define Cpl_Math_real_h_
20#include "colony_config.h"
29#ifndef CPL_MATH_REAL_FLOAT_EPSILON
30#define CPL_MATH_REAL_FLOAT_EPSILON (FLT_EPSILON)
36#ifndef CPL_MATH_REAL_DOUBLE_EPSILON
37#define CPL_MATH_REAL_DOUBLE_EPSILON (DBL_EPSILON)
58 if ( std::isnan( a ) || std::isnan( b ) )
71 T diff = std::abs( a - b );
72 if ( ( a == (T) ( 0.0 ) || b == (T) ( 0.0 ) ) && diff < epsilon )
74 return diff < ( epsilon * epsilon );
78 T absA = std::abs( a );
79 T absB = std::abs( b );
80 return ( diff / ( absA + absB ) ) < epsilon;
88 return almostEquals<float>( a, b, epsilon );
96 return almostEquals<double>( a, b, epsilon );
bool almostEquals(T a, T b, T epsilon)
This template function implements a 'almost equals' comparison function for floating points numbers.
Definition real.h:55
bool areFloatsEqual(float a, float b, float epsilon=CPL_MATH_REAL_FLOAT_EPSILON)
This method is short hand for almostEquals<float> AND provides a default epsilon.
Definition real.h:86
bool areDoublesEqual(double a, double b, double epsilon=CPL_MATH_REAL_DOUBLE_EPSILON)
This method is short hand for almostEquals<double> AND provides a default epsilon.
Definition real.h:94
The 'Cpl' namespace is the root name space for the Colony.
Definition Api16.h:20
#define CPL_MATH_REAL_FLOAT_EPSILON
This symbols provides the default Epsilon value when testing for 'almost equal' between to float numb...
Definition real.h:30
#define CPL_MATH_REAL_DOUBLE_EPSILON
This symbols provides the default Epsilon value when testing for 'almost equal' between to double num...
Definition real.h:37