epsilon.h
Go to the documentation of this file.
00001 /* -*- mode: C++ -*-
00002  *
00003  *  ART epsilon definitions
00004  *
00005  *  Copyright (C) 2009 Austin Robot Technology                    
00006  *  License: Modified BSD Software License Agreement
00007  *
00008  *  $Id: epsilon.h 630 2010-09-25 16:20:42Z jack.oquin $
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;       //< minimal float value
00032   const float distance = 0.01;          //< one centimeter
00033   const float speed = 0.01;             //< in meters/second
00034   const float yaw = angles::from_degrees(1.0); //< in radians
00035 
00036 
00037   // Slightly better AlmostEqual function – still not recommended
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_ //


art_common
Author(s): Austin Robot Technology
autogenerated on Fri Jan 3 2014 11:08:22