diff options
author | Erik Schnetter <schnetter@gmail.com> | 2012-12-01 13:58:22 -0500 |
---|---|---|
committer | Erik Schnetter <schnetter@gmail.com> | 2012-12-01 13:58:22 -0500 |
commit | af41d3bc35d082cb4d8e793071a801b589978ce8 (patch) | |
tree | 8bd5006e6939f3e340e790e29b6f72976a69f210 | |
parent | a3dbc151cd3d9ea06b3c44e66c67284f5d63d443 (diff) | |
download | vecmathlib-af41d3bc35d082cb4d8e793071a801b589978ce8.zip vecmathlib-af41d3bc35d082cb4d8e793071a801b589978ce8.tar.gz |
Implement cosh sinh tanh
-rw-r--r-- | mathfuncs.h | 1 | ||||
-rw-r--r-- | mathfuncs_base.h | 10 | ||||
-rw-r--r-- | mathfuncs_sinh.h | 35 | ||||
-rw-r--r-- | test.cc | 21 | ||||
-rw-r--r-- | vec_base.h | 36 | ||||
-rw-r--r-- | vec_double_avx.h | 8 | ||||
-rw-r--r-- | vec_float.h | 6 |
7 files changed, 106 insertions, 11 deletions
diff --git a/mathfuncs.h b/mathfuncs.h index 697a868..237c396 100644 --- a/mathfuncs.h +++ b/mathfuncs.h @@ -13,6 +13,7 @@ #include "mathfuncs_log.h" #include "mathfuncs_pow.h" #include "mathfuncs_rcp.h" +#include "mathfuncs_sinh.h" #include "mathfuncs_sqrt.h" #endif // #ifndef MATHFUNCS_H diff --git a/mathfuncs_base.h b/mathfuncs_base.h index 5fdcafd..a7207f8 100644 --- a/mathfuncs_base.h +++ b/mathfuncs_base.h @@ -76,6 +76,16 @@ namespace vecmathlib { static realvec_t vml_rcp(realvec_t x); static realvec_t vml_remainder(realvec_t x, realvec_t y); + // sin + static realvec_t vml_cos(realvec_t x); + static realvec_t vml_sin(realvec_t x); + static realvec_t vml_tan(realvec_t x); + + // sinh + static realvec_t vml_cosh(realvec_t x); + static realvec_t vml_sinh(realvec_t x); + static realvec_t vml_tanh(realvec_t x); + // sqrt static realvec_t vml_rsqrt(realvec_t x); static realvec_t vml_sqrt(realvec_t x); diff --git a/mathfuncs_sinh.h b/mathfuncs_sinh.h new file mode 100644 index 0000000..151cd81 --- /dev/null +++ b/mathfuncs_sinh.h @@ -0,0 +1,35 @@ +// -*-C++-*- + +#ifndef MATHFUNCS_SINH_H +#define MATHFUNCS_SINH_H + +#include "mathfuncs_base.h" + +#include <cassert> +#include <cmath> + + + +namespace vecmathlib { + + template<typename realvec_t> + realvec_t mathfuncs<realvec_t>::vml_cosh(realvec_t x) + { + return RV(0.5) * (exp(x) + exp(-x)); + } + + template<typename realvec_t> + realvec_t mathfuncs<realvec_t>::vml_sinh(realvec_t x) + { + return RV(0.5) * (exp(x) - exp(-x)); + } + + template<typename realvec_t> + realvec_t mathfuncs<realvec_t>::vml_tanh(realvec_t x) + { + return sinh(x) / cosh(x); + } + +}; // namespace vecmathlib + +#endif // #ifndef MATHFUNCS_SINH_H @@ -290,15 +290,16 @@ struct vecmathlib_test { // } // } - // void test_sinh() - // { - // for (int i=0; i<imax; ++i) { - // real_t const x = random(-10.0, 10.0); - // check("sinh", sinh, vecmathlib::sinh, x, accuracy); - // check("cosh", cosh, vecmathlib::cosh, x, accuracy); - // check("tanh", tanh, vecmathlib::tanh, x, accuracy); - // } - // } + static void test_sinh() + { + cout << " testing cosh sinh tanh...\n"; + for (int i=0; i<imax; ++i) { + realvec_t const x = random(real_t(-10.0), real_t(+10.0)); + check("sinh", sinh, vecmathlib::sinh, x, accuracy); + check("cosh", cosh, vecmathlib::cosh, x, accuracy); + check("tanh", tanh, vecmathlib::tanh, x, accuracy); + } + } static real_t rsqrt(real_t x) { return real_t(1.0)/sqrt(x); } static void test_sqrt() @@ -331,7 +332,7 @@ struct vecmathlib_test { test_pow(); test_rcp(); // test_sin(); - // test_sinh(); + test_sinh(); test_sqrt(); } }; @@ -183,6 +183,18 @@ namespace vecmathlib { } template<typename real_t, int size> + inline realvec<real_t, size> cos(realvec<real_t, size> x) + { + return x.cos(); + } + + template<typename real_t, int size> + inline realvec<real_t, size> cosh(realvec<real_t, size> x) + { + return x.cosh(); + } + + template<typename real_t, int size> inline realvec<real_t, size> exp(realvec<real_t, size> x) { return x.exp(); @@ -302,11 +314,35 @@ namespace vecmathlib { } template<typename real_t, int size> + inline realvec<real_t, size> sin(realvec<real_t, size> x) + { + return x.sin(); + } + + template<typename real_t, int size> + inline realvec<real_t, size> sinh(realvec<real_t, size> x) + { + return x.sinh(); + } + + template<typename real_t, int size> inline realvec<real_t, size> sqrt(realvec<real_t, size> x) { return x.sqrt(); } + template<typename real_t, int size> + inline realvec<real_t, size> tan(realvec<real_t, size> x) + { + return x.tan(); + } + + template<typename real_t, int size> + inline realvec<real_t, size> tanh(realvec<real_t, size> x) + { + return x.tanh(); + } + template<typename real_t, int size> diff --git a/vec_double_avx.h b/vec_double_avx.h index 21c6d46..b3e8db2 100644 --- a/vec_double_avx.h +++ b/vec_double_avx.h @@ -460,6 +460,8 @@ namespace vecmathlib { realvec atanh() const { return MF::vml_atanh(*this); } realvec ceil() const { return _mm256_ceil_pd(v); } realvec copysign(realvec y) const { return MF::vml_copysign(*this, y); } + realvec cos() const { return MF::vml_cos(*this); } + realvec cosh() const { return MF::vml_cosh(*this); } realvec exp() const { return MF::vml_exp(*this); } realvec exp10() const { return MF::vml_exp10(*this); } realvec exp2() const { return MF::vml_exp2(*this); } @@ -478,10 +480,14 @@ namespace vecmathlib { realvec remainder(realvec y) const { return MF::vml_remainder(*this, y); } realvec round() const { return _mm256_round_pd(v, _MM_FROUND_NINT); } realvec rsqrt() const { return MF::vml_rsqrt(*this); } - boolvec_t signbit() const { return v; } realvec scalbn(intvec_t n) const { return MF::vml_scalbn(*this, n); } + boolvec_t signbit() const { return v; } + realvec sin() const { return MF::vml_sin(*this); } + realvec sinh() const { return MF::vml_sinh(*this); } realvec sqrt() const { return _mm256_sqrt_pd(v); } // realvec sqrt() const { return MF::vml_sqrt(*this); } + realvec tan() const { return MF::vml_tan(*this); } + realvec tanh() const { return MF::vml_tanh(*this); } }; diff --git a/vec_float.h b/vec_float.h index 8404974..4bdc398 100644 --- a/vec_float.h +++ b/vec_float.h @@ -249,6 +249,8 @@ namespace vecmathlib { realvec atanh() const { return MF::vml_atanh(*this); } realvec ceil() const { return MF::vml_ceil(*this); } realvec copysign(realvec y) const { return MF::vml_copysign(*this, y); } + realvec cos() const { return MF::vml_cos(*this); } + realvec cosh() const { return MF::vml_cosh(*this); } realvec exp() const { return MF::vml_exp(*this); } realvec exp10() const { return MF::vml_exp10(*this); } realvec exp2() const { return MF::vml_exp2(*this); } @@ -268,7 +270,11 @@ namespace vecmathlib { realvec rsqrt() const { return MF::vml_rsqrt(*this); } realvec scalbn(intvec_t n) const { return MF::vml_scalbn(*this, n); } boolvec_t signbit() const { return MF::vml_signbit(*this); } + realvec sin() const { return MF::vml_sin(*this); } + realvec sinh() const { return MF::vml_sinh(*this); } realvec sqrt() const { return MF::vml_sqrt(*this); } + realvec tan() const { return MF::vml_tan(*this); } + realvec tanh() const { return MF::vml_tanh(*this); } }; |