chiark / gitweb /
keystrokes
[moebius2.git] / common.h
1 /*
2  * Generally useful stuff.
3  */
4
5 #ifndef COMMON_H
6 #define COMMON_H
7
8 #ifndef _GNU_SOURCE
9 #define _GNU_SOURCE
10 #endif
11
12 #include <math.h>
13 #include <float.h>
14 #include <limits.h>
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <assert.h>
18 #include <errno.h>
19 #include <string.h>
20 #include <unistd.h>
21
22 #include <gsl/gsl_vector.h>
23 #include <gsl/gsl_matrix.h>
24 #include <gsl/gsl_blas.h>
25 #include <gsl/gsl_linalg.h>
26
27 #define D3 3
28
29 double hypotD(const double p[D3], const double q[D3]);
30 double hypotD2(const double p[D3], const double q[D3]);
31 double hypotD2plus(const double p[D3], const double q[D3], double add);
32
33 double magnD(const double pq[D3]);
34 void xprod(double r[D3], const double a[D3], const double b[D3]);
35
36 void flushoutput(void);
37 void diee(const char *what);
38
39 void libdie(const char *lib, int l, const char *str);
40 #define XA(w) ((w) ? (void)0 : libdie("X", __LINE__, #w))
41
42 void gsldie(int l, const char *what, int status);
43 #define GA(w) ({int _ga_r= (w); if (w) gsldie(__LINE__,#w,_ga_r);})
44
45 #define FOR_COORD(k) \
46   for ((k)=0; (k)<D3; (k)++)
47
48 #define K FOR_COORD(k)
49
50 #define GSL_VECTOR(x) gsl_vector x##_gsl= { D3,1,&x[0] };
51 #define GSL_MATRIX(x) gsl_matrix x##_gsl= { D3,D3,D3,&x[0][0] };
52
53 #ifdef FP_FAST_FMA
54 # define fma_fast fma
55 #else
56 # define fma_fast(f1,f2,t) ((f1)*(f2)+(t))
57 #endif
58 #define ffsqa(factor,term) fma_fast((factor),(factor),(term))
59
60 #endif /*COMMON_H*/