[前][次][番号順一覧][スレッド一覧]

ruby-changes:43726

From: nobu <ko1@a...>
Date: Tue, 2 Aug 2016 21:42:46 +0900 (JST)
Subject: [ruby-changes:43726] nobu:r55799 (trunk): math.c: faster tanh

nobu	2016-08-02 21:42:42 +0900 (Tue, 02 Aug 2016)

  New Revision: 55799

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55799

  Log:
    math.c: faster tanh
    
    * math.c (tanh): make faster by the extract form if three
      hyperbolic functions are unavailable.  [Feature #12647]

  Modified files:
    trunk/ChangeLog
    trunk/math.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 55798)
+++ ChangeLog	(revision 55799)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Aug  2 21:42:40 2016  Chia-sheng Chen  <qitar888@g...>
+
+	* 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@r...>
 
 	* ext/socket/option.c, ext/socket/rubysocket.h (inet_ntop): share
Index: math.c
===================================================================
--- math.c	(revision 55798)
+++ math.c	(revision 55799)
@@ -283,8 +283,13 @@ math_sinh(VALUE obj, VALUE x) https://github.com/ruby/ruby/blob/trunk/math.c#L283
 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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]