summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mathfuncs.h1
-rw-r--r--mathfuncs_base.h10
-rw-r--r--mathfuncs_sinh.h35
-rw-r--r--test.cc21
-rw-r--r--vec_base.h36
-rw-r--r--vec_double_avx.h8
-rw-r--r--vec_float.h6
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
diff --git a/test.cc b/test.cc
index f75c981..2fecda5 100644
--- a/test.cc
+++ b/test.cc
@@ -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();
}
};
diff --git a/vec_base.h b/vec_base.h
index 6fa5f4f..f45ccec 100644
--- a/vec_base.h
+++ b/vec_base.h
@@ -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); }
};
OpenPOWER on IntegriCloud