automatic commit
[universe.git] / misc.h
1
2 ////////////////////////////////////////////////////////////////////////////////
3 // This program is free software; you can redistribute it and/or              //
4 // modify it under the terms of the GNU General Public License                //
5 // version 2 as published by the Free Software Foundation.                    //
6 //                                                                            //
7 // This program is distributed in the hope that it will be useful, but        //
8 // WITHOUT ANY WARRANTY; without even the implied warranty of                 //
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU          //
10 // General Public License for more details.                                   //
11 //                                                                            //
12 // Written and (C) by François Fleuret                                        //
13 // Contact <francois.fleuret@epfl.ch> for comments & bug reports              //
14 ////////////////////////////////////////////////////////////////////////////////
15
16 #ifndef MISC_H
17 #define MISC_H
18
19 #include <float.h>
20 #include <stdlib.h>
21
22 #ifdef DEBUG
23 #define ASSERT(x, s) if(!(x)) { std::cerr << "ASSERT FAILED IN " << __FILE__ << ":" << __LINE__ << " [" << (s) << "]\n"; abort(); }
24 #else
25 #define ASSERT(x, s)
26 #endif
27
28 typedef float scalar_t;
29
30 inline scalar_t sq(scalar_t x) { return x*x; }
31
32 inline scalar_t prod_vect(scalar_t x1, scalar_t y1, scalar_t x2, scalar_t y2) {
33   return x1 * y2 - x2 * y1;
34 }
35
36 struct Couple {
37   int index;
38   scalar_t value;
39 };
40
41 int compare_couple(const void *a, const void *b);
42
43 #endif