Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

MathTools.h

Go to the documentation of this file.
00001 // MathTools.h: interface for the MathTools class.
00002 //
00004 
00005 #if !defined(AFX_MATHTOOLS_H__D0539AA7_8BC3_4A5F_99A3_730FAE12C22E__INCLUDED_)
00006 #define AFX_MATHTOOLS_H__D0539AA7_8BC3_4A5F_99A3_730FAE12C22E__INCLUDED_
00007 
00008 #include <math.h>
00009 
00010 class MathTools  {
00011 public:
00012    MathTools() {}
00013    virtual ~MathTools() {}
00014 
00016    static const double pi;
00017 
00019    static const double degrees;
00020 
00021    template<class Number> inline static Number sqr(Number x){ 
00022       return x*x;
00023    }
00024 
00025    template<class Number> inline static int sign(Number x){ 
00026       return x>0 ? 1 : ( x==0 ? 0 : -1);
00027    }
00028 
00030    template<class Number> inline static double setSign(double x, Number sign){
00031       return sign>=0 ? fabs(x) : -fabs(x);
00032    }
00033 
00034    template<class Number> inline static double max(Number a, Number b){
00035       return a>b ? a : b;
00036    }
00037 
00040    inline static double modulus(double x, double y){
00041       double ax=fabs(x), ay=fabs(y);
00042       if(ax>ay) return ax*sqrt(1.0+sqr(ay/ax));
00043       else return (ay==0.0 ? 0.0 : ay*sqrt(1.0+sqr(ax/ay)) );
00044    }
00045    
00046 
00047 };
00048 
00049 #endif // !defined(AFX_MATHTOOLS_H__D0539AA7_8BC3_4A5F_99A3_730FAE12C22E__INCLUDED_)

Thyrix homepageUsers' guide

(C) Arxia 2004-2005