Morph-SynRJ
view mth.cxx @ 0:22de913c2d84
morph-synrj intro
| author | "Cedric Pinson <cedric.pinson@alcove.fr> <mornifle@plopbyte.net>" |
|---|---|
| date | Tue Nov 27 15:23:52 2007 +0100 (2007-11-27) |
| parents | |
| children |
line source
1 /** @file mth.h
2 *
3 * @brief mth facility
4 *
5 *****************************************************************************
6 *
7 * @author psc80
8 *
9 * @date Created 2001/05
10 *
11 * @version $Id: mth.cxx,v 1.4 2004/01/16 23:38:23 psc80 Exp $
12 *
13 ****************************************************************************/
15 #include "mth.h"
18 namespace mth {
20 /// Return the square root
21 float Sqrt(const float& _a) { SYS_ASSERT(_a>=0); return sqrtf(_a);}
22 double Sqrt(const double& _a) { SYS_ASSERT(_a>=0); return sqrt(_a);}
24 float Tan(float _a) { return tan(_a);}
27 float Abs(float _v) { if (_v<0) return -_v; return _v;}
30 /// Return the maximum value between 2 value
31 float Max(const float& a, const float& b) { return a<b? b:a; }
34 /// Return the minimum value between 2 value
35 float Min(const float& a, const float& b) { return a>b? b:a; }
38 float Pow(const float& _a,const float& _b) { return powf(_a,_b);}
40 /// Specialisation of pow for double
41 double Pow(const double& _a,const double& _b) { return pow(_a,_b);}
44 float Frac(const float& _x) { return _x-Floor(_x);}
48 float Clamp(const float& _x,const float& _min,const float& _max) {
49 return Max(Min(_x,_max),_min);}
51 /// Return the cos
52 float Cos(const float& _a) { return cosf((float)_a);}
54 /// Specialisation of cos for double
55 double Cos(const double& _a) { return cos(_a);}
59 /// Return the sin
60 float Sin(const float& _a) { return sinf((float)_a);}
62 /// Specialisation of sin for double
63 double Sin(const double& _a) { return sin(_a);}
67 /// Return the atan
68 float ATan(const float& _a) { return atanf((float)_a);}
70 /// Specialisation of atan for double
71 double ATan(const double& _a) { return atan(_a);}
75 /// Return acos
76 float ACos(const float& _a) { return acosf((float)_a);}
78 /// Specialisation of acos for double
79 double ACos(const double& _a) { return acos(_a);}
83 /// Return asin
84 float ASin(const float& _a) { return asinf((float)_a);}
86 /// Specialisation of asin for double
87 double ASin(const double& _a) { return asin(_a);}
92 /// Return floor
93 float Floor(const float& _a) { return floorf((float)_a);}
95 /// Specialisation of floor for double
96 double Floor(const double& _a) { return floor(_a);}
100 /// Return ceil
101 float Ceil(const float& _a) { return ceilf((float)_a);}
103 /// Specialisation of ceil for double
104 double Ceil(const double& _a) { return ceil(_a);}
109 /// Return sign of a float
110 float Sign(const float& _a) { if (_a<0) return -1; return 1;}
116 /// floathe function returns a pseudo-random integer between 0 and RANDOM_MAX
117 int Rand() { return rand();}
120 /// floathe function returns a pseudo-random integer between 0 and RANDOM_MAX
121 int Random() {
122 static int i=0;
123 srand(i++);
124 return rand();
125 const int NOISE_WRAP_INDEX=256;
126 return (float)((rand() % (NOISE_WRAP_INDEX + NOISE_WRAP_INDEX)) -
127 NOISE_WRAP_INDEX) / NOISE_WRAP_INDEX;
128 //return Rand();
129 }
132 /** The SRand() function sets its argument as the seed for a new
133 * sequence of pseudo-random integers to be returned by rand(). These
134 * sequences are repeatable by calling srand() with the same seed value
135 */
136 void SRand(unsigned int _seed) { srand(_seed);}
144 }
