diff options
Diffstat (limited to 'src/misc.c')
-rw-r--r-- | src/misc.c | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -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)); +} |