diff options
author | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2007-05-29 10:09:00 +0000 |
---|---|---|
committer | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2007-05-29 10:09:00 +0000 |
commit | 7b8b57034998cd6e2fdd9ce3012d8fd923b3e342 (patch) | |
tree | 7c3825b1be977b17aab3282b6cef901f7324d39c /cot.c | |
parent | 2aae11253b2034388eba98efdc136811dd4b4f9c (diff) | |
download | mpfr-7b8b57034998cd6e2fdd9ce3012d8fd923b3e342.tar.gz |
added special code for tiny inputs
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@4501 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'cot.c')
-rw-r--r-- | cot.c | 37 |
1 files changed, 37 insertions, 0 deletions
@@ -34,4 +34,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_coth.) + Near x=0, cot(x) = 1/x - x/3 + ..., more precisely we have + |cot(x) - 1/x| <= 0.36 for |x| <= 1. The error term has + the opposite sign as 1/x, thus |cot(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.36, 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 |cot(x) - 1/x| <= 0.36, if 2^(-2n) ufp(y) >= 0.72, then + |y - cot(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) + 1 <= -2 MAX(PREC(x),PREC(Y)). */ +#define ACTION_TINY(y,x,r) \ + if (MPFR_EXP(x) + 1 <= -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" |