diff options
author | rander <rander.wang@intel.com> | 2017-03-30 15:13:30 +0800 |
---|---|---|
committer | Yang Rong <rong.r.yang@intel.com> | 2017-04-17 16:08:48 +0800 |
commit | 98317483fc7014c8c06b080aeff33661f586e910 (patch) | |
tree | bcffb159d3ef277753ccead18789d7d747a370fa | |
parent | 61318e59c1e9075a76e5abdefb65bd461616afc0 (diff) |
backend: add double version of sinh
cp from fdlibm and pass the cft after refined
Signed-off-by: rander <rander.wang@intel.com>
Tested-by: Yang Rong <rong.r.yang@intel.com>
-rw-r--r-- | backend/src/libocl/tmpl/ocl_math_common.tmpl.cl | 40 | ||||
-rw-r--r-- | backend/src/libocl/tmpl/ocl_math_common.tmpl.h | 1 |
2 files changed, 41 insertions, 0 deletions
diff --git a/backend/src/libocl/tmpl/ocl_math_common.tmpl.cl b/backend/src/libocl/tmpl/ocl_math_common.tmpl.cl index 290ec6b6..378b3b03 100644 --- a/backend/src/libocl/tmpl/ocl_math_common.tmpl.cl +++ b/backend/src/libocl/tmpl/ocl_math_common.tmpl.cl @@ -1732,6 +1732,46 @@ OVERLOADABLE double sin(double x) } } +OVERLOADABLE double sinh(double x) +{ + double one = 1.0, shuge = 1.0e307; + double t,w,h; + int ix,jx; + unsigned lx; + + /* High word of |x|. */ + jx = __HI(x); + ix = jx&0x7fffffff; + + /* x is INF or NaN */ + if(ix>=0x7ff00000) return x+x; + + h = 0.5; + if (jx<0) h = -h; + /* |x| in [0,22], return sign(x)*0.5*(E+E/(E+1))) */ + if (ix < 0x40360000) { /* |x|<22 */ + if (ix<0x3e300000) /* |x|<2**-28 */ + if(shuge+x>one) return x;/* sinh(tiny) = tiny with inexact */ + t = expm1(fabs(x)); + if(ix<0x3ff00000) return h*(2.0*t-t*t/(t+one)); + return h*(t+t/(t+one)); + } + + /* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */ + if (ix < 0x40862E42) return h*exp(fabs(x)); + + /* |x| in [log(maxdouble), overflowthresold] */ + lx = *( (((*(unsigned*)&one)>>29)) + (unsigned*)&x); + if (ix<0x408633CE || ((ix==0x408633ce)&&(lx<=(unsigned)0x8fb9f87d))) { + w = exp(0.5*fabs(x)); + t = h*w; + return t*w; + } + + /* |x| > overflowthresold, sinh(x) overflow */ + return x*shuge; +} + OVERLOADABLE double sqrt(double x) { double z; diff --git a/backend/src/libocl/tmpl/ocl_math_common.tmpl.h b/backend/src/libocl/tmpl/ocl_math_common.tmpl.h index ba246cc0..a7959d33 100644 --- a/backend/src/libocl/tmpl/ocl_math_common.tmpl.h +++ b/backend/src/libocl/tmpl/ocl_math_common.tmpl.h @@ -55,6 +55,7 @@ OVERLOADABLE double nextafter(double x, double y); OVERLOADABLE double rint(double x); OVERLOADABLE double round(double x); OVERLOADABLE double sin(double x); +OVERLOADABLE double sinh(double x); OVERLOADABLE double sqrt(double x); OVERLOADABLE double trunc(double x); |