First cut at lgamma support

git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1228 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
vsc
2005-01-05 17:32:03 +00:00
parent 1bdf9a7876
commit 5792a4f18e
4 changed files with 12219 additions and 3784 deletions

View File

@@ -1077,6 +1077,57 @@ p_atanh(Term t E_ARGS)
RFLOAT(out);
}
/*
lgamma(x) is the logarithm of the gamma function.
*/
static E_FUNC
p_lgamma(Term t E_ARGS)
{
Functor f = AritFunctorOfTerm(t);
union arith_ret v;
blob_type bt;
Float dbl, out;
switch (BlobOfFunctor(f)) {
case long_int_e:
dbl = IntegerOfTerm(t);
break;
case double_e:
dbl = FloatOfTerm(t);
break;
#ifdef USE_GMP
case big_int_e:
dbl = mpz_get_d(Yap_BigIntOfTerm(t));
break;
#endif
default:
/* we've got a full term, need to evaluate it first */
bt = Yap_Eval(t, &v);
/* second case, no need no evaluation */
switch (bt) {
case long_int_e:
dbl = v.Int;
break;
case double_e:
dbl = v.dbl;
break;
#ifdef USE_GMP
case big_int_e:
dbl = mpz_get_d(v.big);
break;
#endif
default:
/* Yap_Error */
RERROR();
}
}
#if HAVE_LGAMMA
out = lgamma(dbl);
#endif
RFLOAT(out);
}
/*
floor(x) maximum integer greatest or equal to X
@@ -1961,6 +2012,7 @@ static InitUnEntry InitUnTab[] = {
{"asin", p_asin},
{"acos", p_acos},
{"atan", p_atan},
{"lgamma", p_lgamma},
{"asinh", p_asinh},
{"acosh", p_acosh},
{"atanh", p_atanh},