3 * Psychlops Standard Library (Universal)
5 * Last Modified 2006/01/04 by Kenchi HOSOKAWA
6 * (C) 2006 Kenchi HOSOKAWA, Kazushi MARUYA and Takao SATO
9 #ifndef HEADER_PSYCHLOPS_MATH_UTIL
10 #define HEADER_PSYCHLOPS_MATH_UTIL
19 extern const double PI;
25 // in this version random(X) generates pseudrandom number in half-closed interval
26 double random(); // [0,1)
27 double random(double N); // [0,N)
28 int random(int N); // [0,N)
29 double random(double min, double max); // [min,max)
30 void random(double array[], int size); // [0,1)
31 void random(double array[], int size, double N); // [0,N)
32 void random(double array[], int size, double min, double max); // [min,max)
34 void random(Matrix &mtx);
35 void random(Matrix &mtx, double factor);
36 void random(Matrix &mtx, double min, double max);
38 void randomize(unsigned long seed);
44 static const double E;
\r
45 static const double LOG2E;
46 inline static double abs(double val) { return (val<0 ? -val : val); }
47 inline static double mod(double lhs, double rhs) { return lhs - floor(lhs/rhs)*rhs; }
48 static int round(double val);
\r
49 static double log2(double val);
\r
56 template <class X, class Y> static double max(X val1, Y val2) { return val1>val2 ? val1 : val2; }
\r
57 template <class X, class Y> static double min(X val1, Y val2) { return val1<val2 ? val1 : val2; }
59 template <class X> static void shuffle(X array, int n);
60 template <class X> static void shuffle(X* array, int n, X init);
61 void setscramble(int array[], unsigned int length); // obsolete
63 static double gaussian(double x, double sigma);
64 static double normalDistibution(double x, double mu, double sigma);
65 static double cumulativeNormalDistibution(double x, double mu, double sigma);
68 // !! this code is copied from http://ray.sakura.ne.jp/tips/shaffle.html
69 template <class X> void Math::shuffle(X array, int n) {
71 for(int i = 1; i < n; i++){
73 std::swap(array[i], array[a]);
76 template <class X> void Math::shuffle(X* array, int n, X init) {
77 for(int i=init; i<n+init; i++) array[i] = i;
81 } /* <- namespace Psycholops */