diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2011-01-17 02:04:11 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2011-01-17 02:04:11 +0000 |
commit | fdba4e8fb18c641205789b9ca808f476e66d40e7 (patch) | |
tree | 19ac30f9031c2ea969d286f37b586052f5b81679 /src | |
parent | e5ff57f6eb62e425122fefd0bc45286c253bead6 (diff) | |
download | mpfr-fdba4e8fb18c641205789b9ca808f476e66d40e7.tar.gz |
Added support for the division-by-zero exception in functions
mpfr_atanh, mpfr_cot, mpfr_coth, mpfr_csc, mpfr_csch,
mpfr_digamma, mpfr_eint, mpfr_gamma, mpfr_lgamma, mpfr_lngamma,
mpfr_log, mpfr_log2 and mpfr_log10.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@7381 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'src')
-rw-r--r-- | src/atanh.c | 5 | ||||
-rw-r--r-- | src/cot.c | 2 | ||||
-rw-r--r-- | src/coth.c | 2 | ||||
-rw-r--r-- | src/csc.c | 2 | ||||
-rw-r--r-- | src/csch.c | 2 | ||||
-rw-r--r-- | src/digamma.c | 1 | ||||
-rw-r--r-- | src/eint.c | 1 | ||||
-rw-r--r-- | src/gamma.c | 1 | ||||
-rw-r--r-- | src/lngamma.c | 5 | ||||
-rw-r--r-- | src/log.c | 1 | ||||
-rw-r--r-- | src/log10.c | 1 | ||||
-rw-r--r-- | src/log2.c | 1 |
12 files changed, 18 insertions, 6 deletions
diff --git a/src/atanh.c b/src/atanh.c index a8d1ee9a4..a48bbbd3f 100644 --- a/src/atanh.c +++ b/src/atanh.c @@ -59,12 +59,13 @@ mpfr_atanh (mpfr_ptr y, mpfr_srcptr xt , mpfr_rnd_t rnd_mode) } /* atanh (x) = NaN as soon as |x| > 1, and arctanh(+/-1) = +/-Inf */ - if (MPFR_UNLIKELY (MPFR_EXP (xt) > 0)) + if (MPFR_UNLIKELY (MPFR_GET_EXP (xt) > 0)) { - if (MPFR_EXP (xt) == 1 && mpfr_powerof2_raw (xt)) + if (MPFR_GET_EXP (xt) == 1 && mpfr_powerof2_raw (xt)) { MPFR_SET_INF (y); MPFR_SET_SAME_SIGN (y, xt); + mpfr_set_divby0 (); MPFR_RET (0); } MPFR_SET_NAN (y); @@ -32,7 +32,7 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., #define ACTION_NAN(y) do { MPFR_SET_NAN(y); MPFR_RET_NAN; } while (1) #define ACTION_INF(y) do { MPFR_SET_NAN(y); MPFR_RET_NAN; } while (1) #define ACTION_ZERO(y,x) do { MPFR_SET_SAME_SIGN(y,x); MPFR_SET_INF(y); \ - MPFR_RET(0); } while (1) + mpfr_set_divby0 (); MPFR_RET(0); } while (1) /* (This analysis is adapted from that for mpfr_coth.) Near x=0, cot(x) = 1/x - x/3 + ..., more precisely we have diff --git a/src/coth.c b/src/coth.c index edab6f19c..88dd93050 100644 --- a/src/coth.c +++ b/src/coth.c @@ -33,7 +33,7 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., #define ACTION_NAN(y) do { MPFR_SET_NAN(y); MPFR_RET_NAN; } while (1) #define ACTION_INF(y) return mpfr_set_si (y, MPFR_IS_POS(x) ? 1 : -1, rnd_mode) #define ACTION_ZERO(y,x) do { MPFR_SET_SAME_SIGN(y,x); MPFR_SET_INF(y); \ - MPFR_RET(0); } while (1) + mpfr_set_divby0 (); MPFR_RET(0); } while (1) /* We know |coth(x)| > 1, thus if the approximation z is such that 1 <= z <= 1 + 2^(-p) where p is the target precision, then the @@ -32,7 +32,7 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., #define ACTION_NAN(y) do { MPFR_SET_NAN(y); MPFR_RET_NAN; } while (1) #define ACTION_INF(y) do { MPFR_SET_NAN(y); MPFR_RET_NAN; } while (1) #define ACTION_ZERO(y,x) do { MPFR_SET_SAME_SIGN(y,x); MPFR_SET_INF(y); \ - MPFR_RET(0); } while (1) + mpfr_set_divby0 (); MPFR_RET(0); } while (1) /* near x=0, we have csc(x) = 1/x + x/6 + ..., more precisely we have |csc(x) - 1/x| <= 0.2 for |x| <= 1. The analysis is similar to that for gamma(x) near x=0 (see gamma.c), except here the error term has the same diff --git a/src/csch.c b/src/csch.c index d15bdd3e4..8f071d3eb 100644 --- a/src/csch.c +++ b/src/csch.c @@ -34,7 +34,7 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., #define ACTION_INF(y) do { MPFR_SET_SAME_SIGN(y,x); MPFR_SET_ZERO (y); \ MPFR_RET(0); } while (1) #define ACTION_ZERO(y,x) do { MPFR_SET_SAME_SIGN(y,x); MPFR_SET_INF(y); \ - MPFR_RET(0); } while (1) + mpfr_set_divby0 (); MPFR_RET(0); } while (1) /* (This analysis is adapted from that for mpfr_csc.) Near x=0, we have csch(x) = 1/x - x/6 + ..., more precisely we have diff --git a/src/digamma.c b/src/digamma.c index b6d48a4a8..7d28d6cb9 100644 --- a/src/digamma.c +++ b/src/digamma.c @@ -307,6 +307,7 @@ mpfr_digamma (mpfr_ptr y, mpfr_srcptr x, mpfr_rnd_t rnd_mode) /* the following works also in case of overlap */ MPFR_SET_INF(y); MPFR_SET_OPPOSITE_SIGN(y, x); + mpfr_set_divby0 (); MPFR_RET(0); } } diff --git a/src/eint.c b/src/eint.c index b5897ba14..70ee3f18c 100644 --- a/src/eint.c +++ b/src/eint.c @@ -222,6 +222,7 @@ mpfr_eint (mpfr_ptr y, mpfr_srcptr x, mpfr_rnd_t rnd) { MPFR_SET_INF(y); MPFR_SET_NEG(y); + mpfr_set_divby0 (); MPFR_RET(0); } } diff --git a/src/gamma.c b/src/gamma.c index f7c1f0aee..8c9619313 100644 --- a/src/gamma.c +++ b/src/gamma.c @@ -135,6 +135,7 @@ mpfr_gamma (mpfr_ptr gamma, mpfr_srcptr x, mpfr_rnd_t rnd_mode) MPFR_ASSERTD(MPFR_IS_ZERO(x)); MPFR_SET_INF(gamma); MPFR_SET_SAME_SIGN(gamma, x); + mpfr_set_divby0 (); MPFR_RET (0); /* exact */ } } diff --git a/src/lngamma.c b/src/lngamma.c index e1c0c00b7..1cdb5f5c5 100644 --- a/src/lngamma.c +++ b/src/lngamma.c @@ -521,6 +521,8 @@ mpfr_lngamma (mpfr_ptr y, mpfr_srcptr x, mpfr_rnd_t rnd) } else /* lngamma(+Inf) = lngamma(+0) = +Inf */ { + if (MPFR_IS_ZERO (x)) + mpfr_set_divby0 (); MPFR_SET_INF (y); MPFR_SET_POS (y); MPFR_RET (0); /* exact */ @@ -557,6 +559,8 @@ mpfr_lgamma (mpfr_ptr y, int *signp, mpfr_srcptr x, mpfr_rnd_t rnd) } else { + if (MPFR_IS_ZERO (x)) + mpfr_set_divby0 (); *signp = MPFR_INT_SIGN (x); MPFR_SET_INF (y); MPFR_SET_POS (y); @@ -570,6 +574,7 @@ mpfr_lgamma (mpfr_ptr y, int *signp, mpfr_srcptr x, mpfr_rnd_t rnd) { MPFR_SET_INF (y); MPFR_SET_POS (y); + mpfr_set_divby0 (); MPFR_RET (0); } @@ -82,6 +82,7 @@ mpfr_log (mpfr_ptr r, mpfr_srcptr a, mpfr_rnd_t rnd_mode) MPFR_ASSERTD (MPFR_IS_ZERO (a)); MPFR_SET_INF (r); MPFR_SET_NEG (r); + mpfr_set_divby0 (); MPFR_RET (0); /* log(0) is an exact -infinity */ } } diff --git a/src/log10.c b/src/log10.c index dfde9a6c5..15502d328 100644 --- a/src/log10.c +++ b/src/log10.c @@ -63,6 +63,7 @@ mpfr_log10 (mpfr_ptr r, mpfr_srcptr a, mpfr_rnd_t rnd_mode) MPFR_ASSERTD (MPFR_IS_ZERO (a)); MPFR_SET_INF (r); MPFR_SET_NEG (r); + mpfr_set_divby0 (); MPFR_RET (0); /* log10(0) is an exact -infinity */ } } diff --git a/src/log2.c b/src/log2.c index cc1dc4542..4ee993faf 100644 --- a/src/log2.c +++ b/src/log2.c @@ -61,6 +61,7 @@ mpfr_log2 (mpfr_ptr r, mpfr_srcptr a, mpfr_rnd_t rnd_mode) MPFR_ASSERTD (MPFR_IS_ZERO (a)); MPFR_SET_INF (r); MPFR_SET_NEG (r); + mpfr_set_divby0 (); MPFR_RET (0); /* log2(0) is an exact -infinity */ } } |