chiark / gitweb /
linear interpolation works; view presets
[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 <sys/types.h>
13 #include <sys/stat.h>
14
15 #include <math.h>
16 #include <float.h>
17 #include <limits.h>
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <assert.h>
21 #include <errno.h>
22 #include <string.h>
23 #include <unistd.h>
24
25 #include <gsl/gsl_vector.h>
26 #include <gsl/gsl_matrix.h>
27 #include <gsl/gsl_blas.h>
28 #include <gsl/gsl_linalg.h>
29 #include <gsl/gsl_interp.h>
30
31 #define D3 3
32
33 double hypotD(const double p[D3], const double q[D3]);
34 double hypotD2(const double p[D3], const double q[D3]);
35 double hypotD2plus(const double p[D3], const double q[D3], double add);
36
37 double magnD(const double pq[D3]);
38 void xprod(double r[D3], const double a[D3], const double b[D3]);
39 double dotprod(const double a[D3], const double b[D3]);
40
41 void flushoutput(void);
42 void diee(const char *what);
43 void fail(const char *emsg);
44
45 void libdie(const char *lib, int l, const char *str);
46 #define XA(w) ((w) ? (void)0 : libdie("X", __LINE__, #w))
47
48 void gsldie(int l, const char *what, int status);
49 #define GA(w) ({int _ga_r= (w); if (w) gsldie(__LINE__,#w,_ga_r);})
50
51 #define FOR_COORD(k) \
52   for ((k)=0; (k)<D3; (k)++)
53
54 #define K FOR_COORD(k)
55
56 #define GSL_VECTOR(x) gsl_vector x##_gsl= { D3,1,&x[0] };
57 #define GSL_MATRIX(x) gsl_matrix x##_gsl= { D3,D3,D3,&x[0][0] };
58
59 #define MIN(a,b) ((a) <= (b) ? (a) : (b))
60 #define MAX(a,b) ((a) >= (b) ? (a) : (b))
61
62 #ifdef FP_FAST_FMA
63 # define fma_fast fma
64 #else
65 # define fma_fast(f1,f2,t) ((f1)*(f2)+(t))
66 #endif
67 #define ffsqa(factor,term) fma_fast((factor),(factor),(term))
68
69 #endif /*COMMON_H*/