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:
parent
1bdf9a7876
commit
5792a4f18e
52
C/arith1.c
52
C/arith1.c
@ -1077,6 +1077,57 @@ p_atanh(Term t E_ARGS)
|
|||||||
RFLOAT(out);
|
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
|
floor(x) maximum integer greatest or equal to X
|
||||||
|
|
||||||
@ -1961,6 +2012,7 @@ static InitUnEntry InitUnTab[] = {
|
|||||||
{"asin", p_asin},
|
{"asin", p_asin},
|
||||||
{"acos", p_acos},
|
{"acos", p_acos},
|
||||||
{"atan", p_atan},
|
{"atan", p_atan},
|
||||||
|
{"lgamma", p_lgamma},
|
||||||
{"asinh", p_asinh},
|
{"asinh", p_asinh},
|
||||||
{"acosh", p_acosh},
|
{"acosh", p_acosh},
|
||||||
{"atanh", p_atanh},
|
{"atanh", p_atanh},
|
||||||
|
@ -165,6 +165,7 @@
|
|||||||
#undef HAVE_ISNAN
|
#undef HAVE_ISNAN
|
||||||
#undef HAVE_KILL
|
#undef HAVE_KILL
|
||||||
#undef HAVE_LABS
|
#undef HAVE_LABS
|
||||||
|
#undef HAVE_LGAMMA
|
||||||
#undef HAVE_LINK
|
#undef HAVE_LINK
|
||||||
#undef HAVE_LOCALTIME
|
#undef HAVE_LOCALTIME
|
||||||
#undef HAVE_LSTAT
|
#undef HAVE_LSTAT
|
||||||
|
@ -963,7 +963,8 @@ AC_CHECK_FUNCS(acosh asinh atanh chdir dlopen dup2)
|
|||||||
AC_CHECK_FUNCS(fesettrapenable finite getcwd getenv)
|
AC_CHECK_FUNCS(fesettrapenable finite getcwd getenv)
|
||||||
AC_CHECK_FUNCS(gethostbyname gethostid gethostname)
|
AC_CHECK_FUNCS(gethostbyname gethostid gethostname)
|
||||||
AC_CHECK_FUNCS(gethrtime getpwnam getrusage gettimeofday getwd)
|
AC_CHECK_FUNCS(gethrtime getpwnam getrusage gettimeofday getwd)
|
||||||
AC_CHECK_FUNCS(isatty isnan kill labs link localtime lstat)
|
AC_CHECK_FUNCS(isatty isnan kill labs link lgamma)
|
||||||
|
AC_CHECK_FUNCS(localtime lstat)
|
||||||
AC_CHECK_FUNCS(memcpy memmove mkstemp mktemp mktime opendir)
|
AC_CHECK_FUNCS(memcpy memmove mkstemp mktemp mktime opendir)
|
||||||
AC_CHECK_FUNCS(putenv rand random readlink regexec)
|
AC_CHECK_FUNCS(putenv rand random readlink regexec)
|
||||||
AC_CHECK_FUNCS(rename rint rl_set_prompt sbrk select)
|
AC_CHECK_FUNCS(rename rint rl_set_prompt sbrk select)
|
||||||
|
Reference in New Issue
Block a user