summaryrefslogtreecommitdiff
path: root/missing/tgamma.c
diff options
context:
space:
mode:
Diffstat (limited to 'missing/tgamma.c')
-rw-r--r--missing/tgamma.c31
1 files changed, 30 insertions, 1 deletions
diff --git a/missing/tgamma.c b/missing/tgamma.c
index 4ace1bcc5f..91f83fcb82 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