summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-02-09 14:45:43 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-02-09 14:45:43 +0000
commitd44f24c47cc0d03135fabb7c764ab23e9d5d1152 (patch)
treeb39a6be0da4ee8e6eff937ee9ea7c0d6bac142dd
parent4d5f46dc088f30df7fc552878da88be552f81bcf (diff)
* missing/tgamma.c (tgamma): use lgamma_r if available.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15420 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog4
-rw-r--r--missing/tgamma.c31
2 files changed, 34 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 079640fff91..2a6aee983e6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Sat Feb 9 23:44:29 2008 Tanaka Akira <akr@fsij.org>
+
+ * missing/tgamma.c (tgamma): use lgamma_r if available.
+
Sat Feb 9 23:22:52 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/bigdecimal/extconf.rb: simplified the condition.
diff --git a/missing/tgamma.c b/missing/tgamma.c
index 4ace1bcc5fe..91f83fcb82f 100644
--- a/missing/tgamma.c
+++ b/missing/tgamma.c
@@ -11,6 +11,35 @@ reference - Haruhiko Okumura: C-gengo niyoru saishin algorithm jiten
***********************************************************/
#include <math.h>
#include <errno.h>
+#include "ruby/config.h"
+
+#ifdef HAVE_LGAMMA_R
+
+double tgamma(double x)
+{
+ int sign;
+ double d;
+ if (x == 0.0) { /* Pole Error */
+ errno = ERANGE;
+ return 1/x < 0 ? -HUGE_VAL : HUGE_VAL;
+ }
+ if (x < 0) {
+ int sign;
+ static double zero = 0.0;
+ double i, f;
+ f = modf(-x, &i);
+ if (f == 0.0) { /* Domain Error */
+ errno = EDOM;
+ return zero/zero;
+ }
+ }
+ d = lgamma_r(x, &sign);
+ return sign * exp(d);
+}
+
+#else
+
+#include <errno.h>
#define PI 3.14159265358979324 /* $\pi$ */
#define LOG_2PI 1.83787706640934548 /* $\log 2\pi$ */
#define N 8
@@ -61,4 +90,4 @@ double tgamma(double x) /* Gamma function */
}
return exp(loggamma(x));
}
-
+#endif