diff options
Diffstat (limited to 'missing/lgamma_r.c')
| -rw-r--r-- | missing/lgamma_r.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/missing/lgamma_r.c b/missing/lgamma_r.c index ba8535b18a..01066d2930 100644 --- a/missing/lgamma_r.c +++ b/missing/lgamma_r.c @@ -8,6 +8,7 @@ reference - Haruhiko Okumura: C-gengo niyoru saishin algorithm jiten http://oku.edu.mie-u.ac.jp/~okumura/algo/ */ +#include "ruby/missing.h" /*********************************************************** gamma.c -- Gamma function ***********************************************************/ @@ -46,6 +47,17 @@ loggamma(double x) /* the natural logarithm of the Gamma function. */ + 0.5 * LOG_2PI - log(v) - x + (x - 0.5) * log(x); } + +#ifdef __MINGW_ATTRIB_PURE +/* get rid of bugs in math.h of mingw */ +#define modf(_X, _Y) __extension__ ({\ + double intpart_modf_bug = intpart_modf_bug;\ + double result_modf_bug = modf((_X), &intpart_modf_bug);\ + *(_Y) = intpart_modf_bug;\ + result_modf_bug;\ +}) +#endif + /* the natural logarithm of the absolute value of the Gamma function */ double lgamma_r(double x, int *signp) @@ -54,7 +66,7 @@ lgamma_r(double x, int *signp) double i, f, s; f = modf(-x, &i); if (f == 0.0) { /* pole error */ - *signp = 1; + *signp = signbit(x) ? -1 : 1; errno = ERANGE; return HUGE_VAL; } |
