Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 #ifndef _EPSILON_H_
00012 #define _EPSILON_H_
00013 
00014 #include <math.h>
00015 #include <angles/angles.h>
00016 
00029 namespace Epsilon
00030 {
00031   const float float_value = 1e-5;       
00032   const float distance = 0.01;          
00033   const float speed = 0.01;             
00034   const float yaw = angles::from_degrees(1.0); 
00035 
00036 
00037   
00038   
00039   inline bool AlmostEqualRelativeOrAbsolute(float A, float B,
00040                                      float maxRelativeError, 
00041                                      float maxAbsoluteError)
00042   {
00043     if (fabs(A - B) < maxAbsoluteError)
00044         return true;
00045 
00046     float relativeError;
00047 
00048     if (fabs(B) > fabs(A))
00049         relativeError = fabs((A - B) / B);
00050     else
00051         relativeError = fabs((A - B) / A);
00052 
00053     if (relativeError <= maxRelativeError)
00054         return true;
00055 
00056     return false;
00057 }
00058 
00059   inline bool equal(float a, float b) {
00060     return AlmostEqualRelativeOrAbsolute(a,b,float_value,float_value);
00061   }
00062 
00063   inline bool lte(float a, float b) {
00064     return ((a<b) || (equal(a,b)));
00065   }
00066 
00067   inline bool gte(float a, float b) {
00068     return ((a>b) || (equal(a,b)));
00069   }
00070 
00071 }
00072 
00073 #endif // _EPSILON_H_ //