chiark / gitweb /
tidyings, more points.
[moebius2.git] / common.c
1 /*
2  * Generally useful stuff.
3  */
4
5 #include "common.h"
6
7 double magnD(const double pq[D3]) {
8   gsl_vector v;
9
10   v.size= D3;
11   v.stride= 1;
12   v.data= (double*)pq;
13   /* owner and block ought not to be used */
14
15   return gsl_blas_dnrm2(&v);
16 }
17
18 double hypotD(const double p[D3], const double q[D3]) {
19   int k;
20   double pq[D3];
21
22   K pq[k]= p[k] - q[k];
23   return magnD(pq);
24 }
25
26 double hypotD2(const double p[D3], const double q[D3]) {
27   int k;
28   double d2= 0;
29   
30   K d2= ffsqa(p[k] - q[k], d2);
31   return d2;
32 }
33
34 double hypotD2plus(const double p[D3], const double q[D3], double d2) {
35   int k;
36   K d2= ffsqa(p[k] - q[k], d2);
37   return d2;
38 }
39
40 void xprod(double r[D3], const double a[D3], const double b[D3]) {
41   r[0]= a[1]*b[2] - a[2]*b[1];
42   r[1]= a[2]*b[0] - a[0]*b[2];
43   r[2]= a[0]*b[1] - a[1]*b[0];
44 }
45
46 void libdie(const char *lib, int l, const char *str) {
47   fprintf(stderr,"%s library call failed, line %d: %s\n", lib, l, str);
48 }
49
50 void gsldie(int l, const char *what, int status) {
51   fprintf(stderr,"gsl function failed, line %d: %s: %s\n",
52           l, what, gsl_strerror(status));
53   exit(-1);
54 }
55
56 void diee(const char *what) { perror(what); exit(16); }
57 void flushoutput(void) { if (fflush(stdout)||ferror(stdout)) diee("stdout"); }