aboutsummaryrefslogtreecommitdiff
path: root/src/misc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/misc.c')
-rw-r--r--src/misc.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/misc.c b/src/misc.c
index e6939f7..f705c74 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -862,3 +862,22 @@ void get_dir(double *dir, double theta, double phi)
dir[1] = sin_theta*sin_phi;
dir[2] = cos_theta;
}
+
+/* Fast version of acos() which uses a lookup table computed on the first call. */
+double fast_acos(double x)
+{
+ size_t i;
+ static int initialized = 0;
+ static double xs[N_ACOS];
+ static double ys[N_ACOS];
+
+ if (!initialized) {
+ for (i = 0; i < LEN(xs); i++) {
+ xs[i] = -1.0 + 2.0*i/(LEN(xs)-1);
+ ys[i] = acos(xs[i]);
+ }
+ initialized = 1;
+ }
+
+ return interp1d(x,xs,ys,LEN(xs));
+}