summaryrefslogtreecommitdiff
path: root/csch.c
diff options
context:
space:
mode:
authorzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2007-05-29 12:24:20 +0000
committerzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2007-05-29 12:24:20 +0000
commit10fa8f5c223a066a1bbe4c290777aa782384f836 (patch)
tree6ef4019ac93c72f1c2e43479855047402f54fc70 /csch.c
parent7b8b57034998cd6e2fdd9ce3012d8fd923b3e342 (diff)
downloadmpfr-10fa8f5c223a066a1bbe4c290777aa782384f836.tar.gz
fixed tiny input problem with csch, j0, j1
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@4502 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'csch.c')
-rw-r--r--csch.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/csch.c b/csch.c
index ad4713287..83e438ae9 100644
--- a/csch.c
+++ b/csch.c
@@ -36,4 +36,41 @@ MA 02110-1301, USA. */
#define ACTION_ZERO(y,x) do { MPFR_SET_SAME_SIGN(y,x); MPFR_SET_INF(y); \
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
+ |csch(x) - 1/x| <= 0.2 for |x| <= 1. The error term has the opposite
+ sign as 1/x, thus |csch(x)| <= |1/x|. Then:
+ (i) either x is a power of two, then 1/x is exactly representable, and
+ as long as 1/2*ulp(1/x) > 0.2, we can conclude;
+ (ii) otherwise assume x has <= n bits, and y has <= n+1 bits, then
+ |y - 1/x| >= 2^(-2n) ufp(y), where ufp means unit in first place.
+ Since |csch(x) - 1/x| <= 0.2, if 2^(-2n) ufp(y) >= 0.4, then
+ |y - csch(x)| >= 2^(-2n-1) ufp(y), and rounding 1/x gives the correct
+ result. If x < 2^E, then y > 2^(-E), thus ufp(y) > 2^(-E-1).
+ A sufficient condition is thus EXP(x) <= -2 MAX(PREC(x),PREC(Y)). */
+#define ACTION_TINY(y,x,r) \
+ if (MPFR_EXP(x) <= -2 * (mp_exp_t) MAX(MPFR_PREC(x), MPFR_PREC(y))) \
+ { \
+ int signx = MPFR_SIGN(x); \
+ inexact = mpfr_ui_div (y, 1, x, r); \
+ if (inexact == 0) /* x is a power of two */ \
+ { /* result always 1/x, except when rounding to zero */ \
+ if (rnd_mode == GMP_RNDU || (rnd_mode == GMP_RNDZ && signx < 0)) \
+ { \
+ if (signx < 0) \
+ mpfr_nextabove (y); /* -2^k + epsilon */ \
+ inexact = 1; \
+ } \
+ else if (rnd_mode == GMP_RNDD || rnd_mode == GMP_RNDZ) \
+ { \
+ if (signx > 0) \
+ mpfr_nextbelow (y); /* 2^k - epsilon */ \
+ inexact = -1; \
+ } \
+ else /* round to nearest */ \
+ inexact = signx; \
+ } \
+ goto end; \
+ }
+
#include "gen_inverse.h"