diff options
Diffstat (limited to 'src/beta.c')
-rw-r--r-- | src/beta.c | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/src/beta.c b/src/beta.c index b2f4154bc..2ab00c16e 100644 --- a/src/beta.c +++ b/src/beta.c @@ -121,21 +121,38 @@ mpfr_beta (mpfr_ptr r, mpfr_srcptr z, mpfr_srcptr w, mpfr_rnd_t rnd_mode) } else /* z or w is 0 */ { - if (mpfr_cmp_ui (z, 0) != 0) /* then w = +0 or -0 */ + /* If x is not a nonpositive integer, Gamma(x) is regular, so that + when y -> 0 with either y >= 0 or y <= 0, + Beta(x,y) ~ Gamma(y) / Gamma(x) + Gamma(y) tends to an infinity of the same sign as y. + Thus Beta(x,y) should be an infinity whose sign is the product + of the signs of y and Gamma(x). */ + if (mpfr_cmp_ui (z, 0) != 0) /* then w is +0 or -0 and z > 0 */ { - /* beta(z,+0) = +Inf, beta(z,-0) = -Inf */ + /* beta(z,+0) = +Inf, beta(z,-0) = -Inf (see above) */ MPFR_SET_INF(r); MPFR_SET_SAME_SIGN(r,w); MPFR_SET_DIVBY0 (); MPFR_RET(0); } - else if (mpfr_cmp_ui (w, 0) != 0) + else if (mpfr_cmp_ui (w, 0) != 0) /* then z is +0 or -0 and w < 0 */ { - /* beta(+0,w) = +Inf, beta(-0,w) = -Inf */ - MPFR_SET_INF(r); - MPFR_SET_SAME_SIGN(r,z); - MPFR_SET_DIVBY0 (); - MPFR_RET(0); + if (mpfr_integer_p (w)) + { + /* When y -> w, |Gamma(y)| -> +Inf but Gamma(y) takes + opposite signs for y < w and y > w, so that the + result is NaN. */ + MPFR_SET_NAN(r); + MPFR_RET_NAN; + } + else + { + /* FIXME concerning the sign (see above) */ + MPFR_SET_INF(r); + MPFR_SET_SAME_SIGN(r,z); + MPFR_SET_DIVBY0 (); + MPFR_RET(0); + } } else /* w = z = 0: beta(+0,+0) = +Inf |