diff options
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | missing/tgamma.c | 31 |
2 files changed, 34 insertions, 1 deletions
@@ -1,3 +1,7 @@ +Sat Feb 9 23:44:29 2008 Tanaka Akira <[email protected]> + + * missing/tgamma.c (tgamma): use lgamma_r if available. + Sat Feb 9 23:22:52 2008 Nobuyoshi Nakada <[email protected]> * ext/bigdecimal/extconf.rb: simplified the condition. 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 |