Go to the documentation of this file.00001
00002 #ifndef MATHFUNS_H
00003 #define MATHFUNS_H
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "Musimat.h"
00019 #include <math.h>
00020
00023
00026 Const Real Pi = 4.0 * atan( 1.0 );
00027
00032
00035 template<class Type> inline Type Abs( Type x ) { Return x < 0 ? -x : x; }
00036
00041 template<class Type> inline Type Mod(Type j, Type k) {
00042 While ( j >= k ) { j = j - k; }
00043 While ( j <= -k ) { j = j + k; }
00044 Return( j );
00045 }
00046
00053 template<class Type> inline Type PosMod( Type j, Type k )
00054 {
00055 While ( j >= k ) {
00056 j = j - k;
00057 }
00058 While ( j < 0 ) {
00059 j = j + k;
00060 }
00061 Return( j );
00062 }
00063
00066 inline Real Floor( Real x ) { Return floor( x ); }
00067
00070 inline Real Ceiling( Real x ) { Return ceil( x ); }
00071
00074 inline Real Sqrt( Real x ) { Return sqrt( x ); }
00075
00079 inline Real Pow( Real x, Real y ) { Return pow( x, y ); }
00080
00084 template<class Type> inline Type Log( Type x ) { Return log( x ); }
00085
00089 template<class Type> inline Type Log10( Type x ) { Return log( x ) / log (10.0); }
00090
00094 template<class Type> inline Type Atan( Type x ) { Return atan( x ); }
00095
00100 template<class Type> inline Type Atan2( Type x, Type y ) { Return atan2( x, y ); }
00101
00105 template<class Type> inline Type Sin( Type x ) { Return sin( x ); }
00106
00110 template<class Type> inline Type Cos( Type x ) { Return cos( x ); }
00111
00117 inline Real unitInterp( Real f, Integer L, Integer U ) {
00118 Return( f * ( U - L ) + L );
00119 }
00120
00128 inline Real linearInterpolate( Integer x, Integer xMin, Integer xMax, Integer yMin, Integer yMax ) {
00129 Real a = Real( x - xMin) / Real(xMax - xMin);
00130 Real b = Real( yMax - yMin );
00131 Return( a * b + yMin );
00132 }
00133
00137 inline Real Round( Real x ) {
00138 Return( Floor( x + 0.5 ) );
00139 }
00140
00145 Integer RealToRational( Real f, Integer Reference a, Integer Reference b);
00146
00148
00154
00156 template <class Type> Type Plus(Type i, Type j) { Return i + j; }
00157
00159 template <class Type> Type Minus(Type i, Type j) { Return i - j; }
00160
00162 template <class Type> Type Divide(Type i, Type j) { Return i / j; }
00163
00165 template <class Type> Type Multiply(Type i, Type j) { Return i * j; }
00167
00168 #endif // MATHFUNS_H