From 83cfc94563c3f5eb0339f4cab280e5219a179a0c Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 2 Aug 2016 12:40:51 +0000 Subject: math.c: tanh overflow * math.c (tanh): check overflows, and return +-1.0. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55798 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- math.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'math.c') diff --git a/math.c b/math.c index a781167d5e..eefcec3c93 100644 --- a/math.c +++ b/math.c @@ -283,7 +283,9 @@ math_sinh(VALUE obj, VALUE x) double tanh(double x) { - return sinh(x) / cosh(x); + const double c = cosh(x); + if (!isinf(c)) return sinh(x) / c; + return x > 0 ? 1.0 : -1.0; } #endif -- cgit v1.2.1