/*
This file is part of liberferfc.
Copyright 2009-2010 by
Laboratoire de l'Informatique du Parallélisme, UMR CNRS - ENS Lyon -
UCB Lyon 1 - INRIA 5668,
and by LORIA (CNRS, INPL, INRIA, UHP, U-Nancy 2).
It has been written by S. Chevillard.
Liberferfc is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
Liberferfc is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with liberferfc. If not, see .
*/
#ifndef H_ERFERFC
#define H_ERFERFC
#include
/* Basic algorithms, as described in the article. */
/* The value x is supposed to be a real positive number. */
/* In particular, the values x=0, x=Inf and x=NaN are not supported. */
/* */
/* Usage: a mpfr_t is created and initialized within the function. */
/* Its precision is automatically set (to the precision t */
/* defined in the article) and it is filled with an */
/* approximation y of f(x) (with f=erf or erfc) such that */
/* |f(x)-y| < 2^{-tprime}*|f(x)| */
/* */
/* Finally, a pointer to this mpfr_t is returned. Whenever */
/* the equation does not provide enough accuracy (when using */
/* erfc3), NULL is returned. */
/* */
/* Since the pointer is created inside the function, it should be */
/* cleared and freed by the final user after having using it. */
/* Example of use: */
/* int main(void) { */
/* mpfr_t x; */
/* mpfr_t *res; */
/* mpfr_init2(x, 10); */
/* mpfr_set_ui(x, 17, MPFR_RNDN); */
/* res = erf1(x, 100); */
/* mpfr_printf("erf(%RNg) ~= %.100RNg\n", x, *res); */
/* mpfr_clear(x); */
/* mpfr_clear(*res); */
/* free(res); */
/* return 0; */
/* } */
mpfr_t *mp_erf1(mpfr_t x, mpfr_prec_t tprime);
mpfr_t *mp_erf2(mpfr_t x, mpfr_prec_t tprime);
mpfr_t *mp_erfc3(mpfr_t x, mpfr_prec_t tprime);
/* Wrappers for computing erf and erfc for any value x. */
/* The best method is automatically chosen in function of x and tprime. */
/* The semantic and the usage are the same as for erf1, erf2 and erfc3. */
mpfr_t *mp_erf(mpfr_t x, mpfr_prec_t tprime);
mpfr_t *mp_erfc(mpfr_t x, mpfr_prec_t tprime);
/* Correctly rounded wrapper. The semantic and usage is exactly the */
/* same as for MPFR functions. In particular, the following program */
/* should always return 1. */
/* int is_correct(mpfr_t x, mpfr_prec_t t, mpfr_rnd_t rnd) { */
/* mpfr_t y1, y2; */
/* int r = 1; */
/* mpfr_init2(y1, t); mpfr_init2(y2, t); */
/* mpfr_erf(y1, x, rnd); cr_erf(y2, x, rnd); */
/* if (!mpfr_equal_p(y1, y2)) r = 0; */
/* mpfr_clear(y1); mpfr_clear(y2); */
/* return r; */
/* } */
int cr_erf(mpfr_t res, mpfr_t x, mpfr_rnd_t rnd);
int cr_erfc(mpfr_t res, mpfr_t x, mpfr_rnd_t rnd);
#endif /* H_ERFERFC */