summaryrefslogtreecommitdiffstats
path: root/missing
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
commitd89bda76aa331e9f89779981346677c4e8e719e9 (patch)
treeb39a6be0da4ee8e6eff937ee9ea7c0d6bac142dd /missing
parent7eb8b7e9044dca59c909e50d4c15355f584252e3 (diff)
downloadruby-d89bda76aa331e9f89779981346677c4e8e719e9.tar.gz
ruby-d89bda76aa331e9f89779981346677c4e8e719e9.tar.xz
ruby-d89bda76aa331e9f89779981346677c4e8e719e9.zip
* missing/tgamma.c (tgamma): use lgamma_r if available.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@15420 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'missing')
-rw-r--r--missing/tgamma.c31
1 files changed, 30 insertions, 1 deletions
diff --git a/missing/tgamma.c b/missing/tgamma.c
index 4ace1bcc5..91f83fcb8 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