mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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
This commit is contained in:
parent
83cfc94563
commit
4483d59fbd
2 changed files with 10 additions and 0 deletions
|
@ -1,3 +1,8 @@
|
|||
Tue Aug 2 21:42:40 2016 Chia-sheng Chen <qitar888@gmail.com>
|
||||
|
||||
* math.c (tanh): make faster by the extract form if three
|
||||
hyperbolic functions are unavailable. [Feature #12647]
|
||||
|
||||
Tue Aug 2 12:37:00 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* ext/socket/option.c, ext/socket/rubysocket.h (inet_ntop): share
|
||||
|
|
5
math.c
5
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
|
||||
|
|
Loading…
Reference in a new issue