diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-08-02 12:40:51 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-08-02 12:40:51 +0000 |
commit | 08b28bfae31522756c91533c18f6314e5b17f2db (patch) | |
tree | 84456645fc0b9232878993c38995c2b3a2e80696 | |
parent | 767059de169a44fd0c67e3f0f58133fd0ba22f68 (diff) | |
download | ruby-08b28bfae31522756c91533c18f6314e5b17f2db.tar.gz |
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
-rw-r--r-- | math.c | 4 | ||||
-rw-r--r-- | test/ruby/test_math.rb | 2 |
2 files changed, 5 insertions, 1 deletions
@@ -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 diff --git a/test/ruby/test_math.rb b/test/ruby/test_math.rb index ac9ab3c961..f226287442 100644 --- a/test/ruby/test_math.rb +++ b/test/ruby/test_math.rb @@ -111,6 +111,8 @@ class TestMath < Test::Unit::TestCase check(Math.sinh(0) / Math.cosh(0), Math.tanh(0)) check(Math.sinh(1) / Math.cosh(1), Math.tanh(1)) check(Math.sinh(2) / Math.cosh(2), Math.tanh(2)) + check(+1.0, Math.tanh(+1000.0)) + check(-1.0, Math.tanh(-1000.0)) end def test_acosh |