mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
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
This commit is contained in:
parent
aa8e9c63ad
commit
83cfc94563
2 changed files with 5 additions and 1 deletions
4
math.c
4
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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue