• Main Page
  • Modules
  • Classes
  • Files
  • File List
  • File Members

/Users/garethloy/Musimathics/Musimat1.2/include/MathFuns.h

Go to the documentation of this file.
00001 /* $Revision: 1.4 $ $Date: 2006/09/07 08:38:33 $ $Author: dgl $ $Name:  $ $Id: MathFuns.h,v 1.4 2006/09/07 08:38:33 dgl Exp $ */
00002 #ifndef MATHFUNS_H
00003 #define MATHFUNS_H
00004 
00005 // The Musimat Tutorial © 2006 Gareth Loy
00006 // Derived from Chapter 9 and Appendix B of "Musimathics Vol. 1" © 2006 Gareth Loy 
00007 // and published exclusively by The MIT Press.
00008 // This program is released WITHOUT ANY WARRANTY; without even the implied 
00009 // warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
00010 // For information on usage and redistribution, and for a DISCLAIMER OF ALL
00011 // WARRANTIES, see the file, "LICENSE.txt," in this distribution.
00012 // "Musimathics" is available here:     http://mitpress.mit.edu/catalog/item/default.asp?ttype=2&tid=10916
00013 // Gareth Loy's Musimathics website:    http://www.musimathics.com/
00014 // The Musimat website:                 http://www.musimat.com/
00015 // This program is released under the terms of the GNU General Public License
00016 // available here:                      http://www.gnu.org/licenses/gpl.txt
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); // Real division
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

Generated on Fri Nov 26 2010 16:18:25 for MusimatLib by  doxygen 1.7.2