Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | Related Pages

FWMath.h

00001 /* -*- mode:c++ -*- ********************************************************
00002  * file:        FWMath.h
00003  *
00004  * author:      Christian Frank
00005  *
00006  * copyright:   (C) 2004 Telecommunication Networks Group (TKN) at
00007  *              Technische Universitaet Berlin, Germany.
00008  *
00009  *              This program is free software; you can redistribute it
00010  *              and/or modify it under the terms of the GNU General Public
00011  *              License as published by the Free Software Foundation; either
00012  *              version 2 of the License, or (at your option) any later
00013  *              version.
00014  *              For further information see file COPYING
00015  *              in the top level directory
00016  ***************************************************************************
00017  * part of:     framework implementation developed by tkn
00018  **************************************************************************/
00019 
00020 #ifndef FWMATH_H
00021 #define FWMATH_H
00022 
00023 //
00024 // Support functions for mathematical operations
00025 //
00026 
00027 #include <math.h>
00028 
00029 
00030 /* windows math.h doesn't define the PI variable so we have to do it
00031    by hand*/
00032 #ifndef M_PI
00033 #define M_PI 3.14159265358979323846
00034 #endif
00035 
00036 /* Constant for comparing doubles. Two doubles at most epsilon apart
00037    are declared equal.*/
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

Generated on Fri Jan 12 08:29:32 2007 for Mobility Framework by  doxygen 1.4.4