ruby-changes:43725
From: nobu <ko1@a...>
Date: Tue, 2 Aug 2016 21:40:56 +0900 (JST)
Subject: [ruby-changes:43725] nobu:r55798 (trunk): math.c: tanh overflow
nobu 2016-08-02 21:40:51 +0900 (Tue, 02 Aug 2016) New Revision: 55798 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55798 Log: math.c: tanh overflow * math.c (tanh): check overflows, and return +-1.0. Modified files: trunk/math.c trunk/test/ruby/test_math.rb Index: math.c =================================================================== --- math.c (revision 55797) +++ math.c (revision 55798) @@ -283,7 +283,9 @@ math_sinh(VALUE obj, VALUE x) https://github.com/ruby/ruby/blob/trunk/math.c#L283 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 Index: test/ruby/test_math.rb =================================================================== --- test/ruby/test_math.rb (revision 55797) +++ test/ruby/test_math.rb (revision 55798) @@ -111,6 +111,8 @@ class TestMath < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_math.rb#L111 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/