mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
4d5f46dc08
commit
d44f24c47c
2 changed files with 34 additions and 1 deletions
|
@ -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.
|
||||
|
|
|
@ -10,6 +10,35 @@ reference - Haruhiko Okumura: C-gengo niyoru saishin algorithm jiten
|
|||
gamma.c -- Gamma function
|
||||
***********************************************************/
|
||||
#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$ */
|
||||
|
@ -61,4 +90,4 @@ double tgamma(double x) /* Gamma function */
|
|||
}
|
||||
return exp(loggamma(x));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue