Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members   Examples  

mj_math.h

Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 
00003 /* COPYRIGHT
00004  *
00005  * This file is part of Mustajuuri LGPL modules.
00006  *
00007  * Author: Tommi Ilmonen, 1999-2001.
00008  * Tommi.Ilmonen@hut.fi
00009  *
00010  * http://www.tml.hut.fi/~tilmonen/mustajuuri/
00011  *
00012  *
00013  * This file is licensed under the Lesser GNU Public License
00014  * (LGPL). Extra clauses can be found from the file MUSTAJUURI_LGPL and
00015  * further explanations from the file MUSTAJUURI_LICENSE. The license
00016  * text can be found in file "LGPL.txt".
00017  *
00018  * If you want a parallel license (for commercial reasons for example),
00019  * you should negotiate the matter with the author(s).
00020  *    
00021  */
00022 
00023 #ifndef MJ_MATH_H
00024 #define MJ_MATH_H
00025 
00026 #include <math.h>
00027 
00028 
00054 
00055 #define MJ_pi  3.1415926535897931
00056 
00057 #define MJ_2pi 6.2831853071795862
00058 
00059 #define MJ_piSquared 9.869604401089358
00060 
00061 #define MJ_pi2 1.57079632679489660000
00062 
00063 #define MJ_pi4 0.78539816339744828
00064 
00066 #define MJ_ln2 0.693147180559945290
00067 
00068 #define MJ_ln22 0.346573590279972640
00069 
00070 
00071 /* Float wrappers. */
00072 
00073 inline float MJ_cos(float v)
00074 {
00075   return cosf(v);
00076 }
00077 
00078 inline float MJ_log(float v)
00079 {
00080   return logf(v);
00081 }
00082 
00083 inline float MJ_exp(float v)
00084 {
00085   return expf(v);
00086 }
00087 
00088 inline float MJ_pow(float v, float power)
00089 {
00090   return powf(v, power);
00091 }
00092 
00093 inline float MJ_square(float v)
00094 {
00095   return v * v;
00096 }
00097 
00098 inline float MJ_sin(float v)
00099 {
00100   return sinf(v);
00101 }
00102 
00103 inline float MJ_sinh(float v)
00104 {
00105   return sinhf(v);
00106 }
00107 
00108 inline float MJ_sqrt(float v)
00109 {
00110   return sqrtf(v);
00111 }
00112 
00113 inline float MJ_tan(float v)
00114 {
00115   return tanf(v);
00116 }
00117 
00118 inline float MJ_atan2(float v, float u)
00119 {
00120   return atan2f(v,u);
00121 }
00122 
00123 /* Double wrappers. */
00124 
00125 inline double MJ_cos(double v)
00126 {
00127   return cos(v);
00128 }
00129 
00130 inline double MJ_log(double v)
00131 {
00132   return log(v);
00133 }
00134 
00135 inline double MJ_exp(double v)
00136 {
00137   return exp(v);
00138 }
00139 
00140 inline double MJ_pow(double v, double power)
00141 {
00142   return pow(v, power);
00143 }
00144 
00145 inline double MJ_square(double v)
00146 {
00147   return v * v;
00148 }
00149 
00150 inline double MJ_sin(double v)
00151 {
00152   return sin(v);
00153 }
00154 
00155 inline double MJ_sinh(double v)
00156 {
00157   return sinh(v);
00158 }
00159 
00160 inline double MJ_sqrt(double v)
00161 {
00162   return sqrt(v);
00163 }
00164 
00165 inline double MJ_tan(double v)
00166 {
00167   return tan(v);
00168 }
00169 
00170 inline double MJ_atan2(double v, double u)
00171 {
00172   return atan2(v,u);
00173 }
00174 
00175 // Clamp (limit) to the given range
00176 
00177 inline double MJ_clamp(double v, double min, double max)
00178 {
00179   if(v < min) return min;
00180   if(v > max) return max;
00181   return v;
00182 }
00183 
00184 inline double MJ_clampD(double v, double min, double max)
00185 {
00186   if(v < min) return min;
00187   if(v > max) return max;
00188   return v;
00189 }
00190 
00191 inline float MJ_clamp(float v, float min, float max)
00192 {
00193   if(v < min) return min;
00194   if(v > max) return max;
00195   return v;
00196 }
00197 
00198 inline float MJ_clampF(float v, float min, float max)
00199 {
00200   if(v < min) return min;
00201   if(v > max) return max;
00202   return v;
00203 }
00204 
00205 inline int MJ_clamp(int v, int min, int max)
00206 {
00207   if(v < min) return min;
00208   if(v > max) return max;
00209   return v;
00210 }
00211 
00212 
00213 // Minmimum value
00214 
00215 inline float MJ_min(float x1, float x2)
00216 {
00217   if(x1 > x2) return x2;
00218   return x1;
00219 }
00220 
00221 inline double MJ_min(double x1, double x2)
00222 {
00223   if(x1 > x2) return x2;
00224   return x1;
00225 }
00226 
00227 inline int MJ_min(int x1, int x2)
00228 {
00229   if(x1 > x2) return x2;
00230   return x1;
00231 }
00232 
00233 inline long MJ_min(long x1, long x2)
00234 {
00235   if(x1 > x2) return x2;
00236   return x1;
00237 }
00238 
00239 inline unsigned MJ_min(unsigned x1, unsigned x2)
00240 {
00241   if(x1 > x2) return x2;
00242   return x1;
00243 }
00244 
00245 inline unsigned long MJ_min(unsigned long x1, unsigned long x2)
00246 {
00247   if(x1 > x2) return x2;
00248   return x1;
00249 }
00250 
00251 // Maximum value
00252 
00253 inline float MJ_max(float x1, float x2)
00254 {
00255   if(x1 > x2) return x1;
00256   return x2;
00257 }
00258 
00259 inline double MJ_max(double x1, double x2)
00260 {
00261   if(x1 > x2) return x1;
00262   return x2;
00263 }
00264 
00265 inline int MJ_max(int x1, int x2)
00266 {
00267   if(x1 > x2) return x1;
00268   return x2;
00269 }
00270 
00271 inline unsigned MJ_max(unsigned x1, unsigned x2)
00272 {
00273   if(x1 > x2) return x1;
00274   return x2;
00275 }
00276 
00277 inline unsigned long MJ_max(unsigned long x1, unsigned long x2)
00278 {
00279   if(x1 > x2) return x1;
00280   return x2;
00281 }
00282 
00284 
00285 inline float MJ_abs(float x1)
00286 {
00287   if(x1 > 0.0) return x1;
00288   else return -x1;
00289 }
00290 
00291 inline double MJ_abs(double x1)
00292 {
00293   if(x1 > 0.0) return x1;
00294   else return -x1;
00295 }
00296 
00297 inline int MJ_abs(int x1)
00298 {
00299   if(x1 > 0) return x1;
00300   else return -x1;
00301 }
00302 
00303 inline long MJ_abs(long x1)
00304 {
00305   if(x1 > 0) return x1;
00306   else return -x1;
00307 }
00308 
00310 inline unsigned long MJ_abs(unsigned long x1)
00311 {
00312   return x1;
00313 }
00314 
00315 //@name Decibel conversions
00317 
00318 inline double MJ_absToDb(double d)
00319 { return (log10(d)) * 20.0; }
00320 inline double MJ_squareToDb(double d)
00321 { return (log10(d)) * 10.0; }
00323 inline double MJ_absToDb(double d, double clip)
00324 {
00325   double tmp = (log10(d)) * 20.0;
00326   return tmp > clip ? tmp : clip;
00327 }
00329 inline double MJ_dbToAbs(double d)
00330 {  return pow(10.0, d * 0.05); }
00331 inline double MJ_dbToSquare(double d)
00332 { return pow(10.0, d * 0.1); }
00333 
00335 inline float MJ_absToDb(float d)
00336 { return (log10f(d)) * 20.0; }
00337 inline float MJ_squareToDb(float d)
00338 { return (log10f(d)) * 10.0; }
00340 inline float MJ_dbToAbs(float d)
00341 { return powf(10.0, d * 0.05); }
00342 inline float MJ_dbToSquare(float d)
00343 { return powf(10.0, d * 0.1); }
00345 
00347 inline float MJ_centToMul(float cents)
00348 {
00349   return powf(2.0, cents / 1200.0);
00350 }
00352 inline float MJ_mulToCent(float mul)
00353 { return logf(mul) / MJ_ln2 * 1200.0; }
00354 
00356 inline double MJ_centToMul(double cents)
00357 { return pow(2.0, cents / 1200.0); }
00359 inline double MJ_mulToCent(double mul)
00360 { return log(mul) / MJ_ln2 * 1200.0; }
00361 
00362 #endif

Generated at Sun Jan 18 20:51:22 2004 for Jezabel by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001