From 43a1a754dd3699edb85e1dfdf50d1fa66799100e Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Fri, 5 Mar 2010 00:01:04 +0000 Subject: [PATCH] erf function (patch from Bernd Gutmann). --- C/arith1.c | 22 ++++++++++++++++++++++ H/eval.h | 2 ++ config.h.in | 1 + configure | 10 ++++++---- configure.in | 2 +- docs/yap.tex | 6 ++++++ 6 files changed, 38 insertions(+), 5 deletions(-) diff --git a/C/arith1.c b/C/arith1.c index 86ab48c31..49d6fe112 100644 --- a/C/arith1.c +++ b/C/arith1.c @@ -418,6 +418,26 @@ eval1(Int fi, Term t) { RERROR(); #endif } + case op_erf: + { + Float dbl = get_float(t), out; +#if HAVE_ERF + out = erf(dbl); + RFLOAT(out); +#else + RERROR(); +#endif + } + case op_erfc: + { + Float dbl = get_float(t), out; +#if HAVE_ERF + out = erfc(dbl); + RFLOAT(out); +#else + RERROR(); +#endif + } /* floor(x) maximum integer greatest or equal to X @@ -814,6 +834,8 @@ static InitUnEntry InitUnTab[] = { {"float_integer_part", op_fintp}, {"sign", op_sign}, {"lgamma", op_lgamma}, + {"erf",op_erf}, + {"erfc",op_erfc}, {"random", op_random1} }; diff --git a/H/eval.h b/H/eval.h index e1cb2916b..8319e2a4e 100644 --- a/H/eval.h +++ b/H/eval.h @@ -93,6 +93,8 @@ typedef enum { op_fintp, op_sign, op_lgamma, + op_erf, + op_erfc, op_random1 } arith1_op; diff --git a/config.h.in b/config.h.in index 7c353fe5c..772d08d30 100755 --- a/config.h.in +++ b/config.h.in @@ -160,6 +160,7 @@ #undef HAVE_CTIME #undef HAVE_DLOPEN #undef HAVE_DUP2 +#undef HAVE_ERF #undef HAVE_FECLEAREXCEPT #undef HAVE_FESETTRAPENABLE #undef HAVE_FETESTEXCEPT diff --git a/configure b/configure index 3aff7acf8..c19032f7f 100755 --- a/configure +++ b/configure @@ -8499,12 +8499,14 @@ _ACEOF fi done -for ac_func in feclearexcept +for ac_func in erf feclearexcept do : - ac_fn_c_check_func "$LINENO" "feclearexcept" "ac_cv_func_feclearexcept" -if test "x$ac_cv_func_feclearexcept" = x""yes; then : + as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` +ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" +eval as_val=\$$as_ac_var + if test "x$as_val" = x""yes; then : cat >>confdefs.h <<_ACEOF -#define HAVE_FECLEAREXCEPT 1 +#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 _ACEOF fi diff --git a/configure.in b/configure.in index d9b656da9..d5232b90a 100755 --- a/configure.in +++ b/configure.in @@ -1501,7 +1501,7 @@ dnl Checks for library functions. AC_TYPE_SIGNAL AC_CHECK_FUNCS(access) AC_CHECK_FUNCS(acosh asinh atanh chdir ctime dlopen dup2) -AC_CHECK_FUNCS(feclearexcept) +AC_CHECK_FUNCS(erf feclearexcept) AC_CHECK_FUNCS(fesettrapenable fgetpos finite fpclass ftime getcwd getenv) AC_CHECK_FUNCS(gethostbyname gethostid gethostname) AC_CHECK_FUNCS(gethrtime getpagesize) diff --git a/docs/yap.tex b/docs/yap.tex index ae34dfb3b..b5d4701e8 100644 --- a/docs/yap.tex +++ b/docs/yap.tex @@ -3849,6 +3849,12 @@ Hyperbolic arc tangent. @item lgamma(@var{X}) gamma function. +@item erf(@var{X}) +gaussian error function. + +@item erfc(@var{X}) +complementary gaussian error function. + @item random(@var{X}) [ISO] An integer random number between 0 and @var{X}.