00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef FWMATH_H
00021 #define FWMATH_H
00022
00023
00024
00025
00026
00027 #include <math.h>
00028
00029
00030
00031
00032 #ifndef M_PI
00033 #define M_PI 3.14159265358979323846
00034 #endif
00035
00036
00037
00038 #ifndef EPSILON
00039 #define EPSILON 0.001
00040 #endif
00041
00042
00052 class FWMath {
00053
00054 public:
00055
00059 static double mod(double dividend, double divisor) {
00060 double i;
00061 return modf(dividend/divisor, &i)*divisor;
00062 }
00063
00067 static double div(double dividend, double divisor) {
00068 double i;
00069 double f;
00070 f=modf(dividend/divisor, &i);
00071 return i;
00072 }
00073
00079 static bool close(double one, double two) {
00080 return fabs(one-two)<EPSILON;
00081 }
00082
00087 static int stepfunction(double i) { return (i>EPSILON) ? 1 : close(i,0) ? 0 :-1; };
00088
00089
00093 static int sign(double i) { return (i>=0)? 1 : -1; };
00094
00098 static int round(double d) { return (int)(ceil(d-0.5)); }
00099
00103 static double max(double a, double b) { return (a<b)? b : a; }
00104
00108 static double dBm2mW(double dBm){
00109 return pow(10.0, dBm/10.0);
00110 }
00111
00116 static inline double torDist (double x1, double x2, double y1, double y2) {
00117 return (x1-x2) * (x1-x2) + (y1-y2) * (y1-y2);
00118 };
00119 };
00120
00121 #endif