Schnek
functions.hpp
1 /*
2  * functions.hpp
3  *
4  * Created on: 23 Jan 2007
5  * Author: Holger Schmitz
6  * Email: holger@notjustphysics.com
7  *
8  * Copyright 2012 Holger Schmitz
9  *
10  * This file is part of Schnek.
11  *
12  * Schnek is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation, either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * Schnek is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with Schnek. If not, see <http://www.gnu.org/licenses/>.
24  *
25  */
26 
27 #ifndef SCHNEK_FUNCTIONS_H_
28 #define SCHNEK_FUNCTIONS_H_
29 
30 namespace schnek {
31 
32 template<typename T>
33 T min(T a, T b) { return a>b?b:a; }
34 
35 template<typename T>
36 T max(T a, T b) { return a>b?a:b; }
37 
38 template<typename T>
39 int signum0(T x) { return x>0?1:(x<0?-1:0); }
40 
41 template<typename T>
42 int signum(T x) { return x<0?-1:1; }
43 
44 double drand();
45 
46 int irand(int range);
47 
48 template<class ArrayType>
49 void crossProduct(ArrayType &result, const ArrayType &a, const ArrayType &b)
50 {
51  result[0] = a[1]*b[2] - a[2]*b[1];
52  result[1] = a[2]*b[0] - a[0]*b[2];
53  result[2] = a[0]*b[1] - a[1]*b[0];
54 }
55 
56 } // namespace
57 
58 #endif // SCHNEK_FUNCTIONS_H_
Definition: algo.hpp:30