X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=moebius2.git;a=blobdiff_plain;f=common.c;h=3b036aaa29f54508a5708a1965347734dc5cfa5e;hp=bc4dcaef8ec8e837337babe47a7635e5534d43bd;hb=30d841cc8a4e2ae0bec21b58e3c73057e4286f06;hpb=2e8e765ae894f9921fa97db2f21915662f162224 diff --git a/common.c b/common.c index bc4dcae..3b036aa 100644 --- a/common.c +++ b/common.c @@ -15,6 +15,14 @@ double magnD(const double pq[D3]) { return gsl_blas_dnrm2(&v); } +double magnD2(const double pq[D3]) { + int k; + double d2= 0; + + K d2= ffsqa(pq[k], d2); + return d2; +} + double hypotD(const double p[D3], const double q[D3]) { int k; double pq[D3]; @@ -43,5 +51,35 @@ void xprod(double r[D3], const double a[D3], const double b[D3]) { r[2]= a[0]*b[1] - a[1]*b[0]; } +void normalise(double v[D3], double one, double absepsilon) { + int k; + double multby= one/(magnD(v) + absepsilon); + K v[k] *= multby; +} + +void xprod_norm(double r[D3], const double a[D3], const double b[D3], + double one, double absepsilon) { + xprod(r,a,b); + normalise(r, absepsilon, one); +} + +double dotprod(const double a[D3], const double b[D3]) { + int k; + double result= 0; + K result += a[k] * b[k]; + return result; +} + +void libdie(const char *lib, int l, const char *str) { + fprintf(stderr,"%s library call failed, line %d: %s\n", lib, l, str); +} + +void gsldie(int l, const char *what, int status) { + fprintf(stderr,"gsl function failed, line %d: %s: %s\n", + l, what, gsl_strerror(status)); + exit(-1); +} + void diee(const char *what) { perror(what); exit(16); } -void flushoutput(void) { if (fflush(stdout)||ferror(stdout)) diee("stdout"); } +void fail(const char *emsg) { fputs(emsg,stderr); exit(12); } +void flushoutput(void) { if (ferror(stdout)||fflush(stdout)) diee("stdout"); }