aboutsummaryrefslogtreecommitdiffstats
path: root/math.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-08-02 12:42:42 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-08-02 12:42:42 +0000
commit8c9c245d6e783413ade607950a6db98e02522e6f (patch)
tree062864922f4a5c2f1d9a3b3eaf1bedf1aaad79ba /math.c
parent08b28bfae31522756c91533c18f6314e5b17f2db (diff)
downloadruby-8c9c245d6e783413ade607950a6db98e02522e6f.tar.gz
math.c: faster tanh
* math.c (tanh): make faster by the extract form if three hyperbolic functions are unavailable. [Feature #12647] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55799 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'math.c')
-rw-r--r--math.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/math.c b/math.c
index eefcec3c93..b15e87113c 100644
--- a/math.c
+++ b/math.c
@@ -283,8 +283,13 @@ math_sinh(VALUE obj, VALUE x)
double
tanh(double x)
{
+# if defined(HAVE_SINH) && defined(HAVE_COSH)
const double c = cosh(x);
if (!isinf(c)) return sinh(x) / c;
+# else
+ const double e = exp(x+x);
+ if (!isinf(e)) return (e - 1) / (e + 1);
+# endif
return x > 0 ? 1.0 : -1.0;
}
#endif