diff options
author | Erik Schnetter <schnetter@gmail.com> | 2013-01-30 14:08:56 -0500 |
---|---|---|
committer | Erik Schnetter <schnetter@gmail.com> | 2013-01-30 14:08:56 -0500 |
commit | 7c57d56db52f2b439f1fe3dae40b1acbdbddd896 (patch) | |
tree | 92c206d124b0a058abcf0800bf370e5578769a0a | |
parent | 56e82a48448becfc39f8686cd26c3f31a30594a3 (diff) | |
download | vecmathlib-7c57d56db52f2b439f1fe3dae40b1acbdbddd896.zip vecmathlib-7c57d56db52f2b439f1fe3dae40b1acbdbddd896.tar.gz |
Optimise exp(); explain number of iterations
-rw-r--r-- | mathfuncs_exp.h | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/mathfuncs_exp.h b/mathfuncs_exp.h index 851e6f9..4f4bf61 100644 --- a/mathfuncs_exp.h +++ b/mathfuncs_exp.h @@ -22,9 +22,17 @@ namespace vecmathlib { intvec_t iround_x = convert_int(round_x); // Approximate - assert(all(x >= RV(-0.5) && x <= RV(0.5))); // exp(x) = Sum[n=0,nmax] x^n / n! - int const nmax = 15; + assert(all(x >= RV(-0.5) && x <= RV(0.5))); + + // nmax max_error + // 5 4.2e-5 + // 6 2.4e-6 + // 7 1.2e-7 + // 11 2.2e-13 + // 12 6.3e-15 + // 13 1.7e-16 + int const nmax = sizeof(real_t)==4 ? 7 : 11; x *= RV(M_LN2); realvec_t y = x; // x^n / n! realvec_t r = RV(1.0) + y; |