Open
Graph Drawing
Framework

 v.2010.10
 

math.h

Go to the documentation of this file.
00001 /*
00002  * $Revision: 2027 $
00003  * 
00004  * last checkin:
00005  *   $Author: gutwenger $ 
00006  *   $Date: 2010-09-01 11:55:17 +0200 (Wed, 01 Sep 2010) $ 
00007  ***************************************************************/
00008  
00052 #ifndef OGDF_MATH_H
00053 #define OGDF_MATH_H
00054 
00055 namespace ogdf {
00056 
00057 #define DOUBLE_EPS 0.000001
00058 
00059 class OGDF_EXPORT Math {
00060 public:
00061     inline static int binomial(int n, int k) {
00062         if(k>n/2) k = n-k;
00063         int r = n;
00064         for(int i = 2; i<=k; ++i)
00065             r = (r * (n+1-i))/i;
00066         return r;
00067     }
00068     inline static double binomial(double n, double k) {
00069         if(k>n/2) k = n-k;
00070         double r = n;
00071         for(int i = 2; i<=k; ++i)
00072             r = (r * (n+1-i))/i;
00073         return r;
00074     }
00075     static int factorial(int n) {
00076         int r = 1;
00077         for(; n>1; --n) r *= n;
00078         return r;
00079     }
00080 
00081     static double factorial(double n) {
00082         double r = 1;
00083         for(; n>1; --n) r *= n;
00084         return r;
00085     }
00086 
00087     inline bool equald(double a, double b) {
00088         double d = a-b;
00089         return d < DOUBLE_EPS && d > -DOUBLE_EPS;
00090     }
00091 };
00092 
00093 
00094 }
00095 
00096 #endif // OGDF_MATH_H