diff options
author | zimmerma <zimmerma@211d60ee-9f03-0410-a15a-8952a2c7a4e4> | 2013-12-21 09:25:05 +0000 |
---|---|---|
committer | zimmerma <zimmerma@211d60ee-9f03-0410-a15a-8952a2c7a4e4> | 2013-12-21 09:25:05 +0000 |
commit | de2b7e9f3c17892b585ea51ef622c02fea4e8f26 (patch) | |
tree | 04490c1aa16afd08b413261514c5b6e5a30b398a | |
parent | 412a3653481a63e3eb558450a3f6d418ab8b3a7f (diff) | |
download | mpc-de2b7e9f3c17892b585ea51ef622c02fea4e8f26.tar.gz |
improve starting precision when input is tiny
git-svn-id: svn://scm.gforge.inria.fr/svn/mpc/trunk@1400 211d60ee-9f03-0410-a15a-8952a2c7a4e4
-rw-r--r-- | src/sin_cos.c | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/sin_cos.c b/src/sin_cos.c index fe44c42..7051708 100644 --- a/src/sin_cos.c +++ b/src/sin_cos.c @@ -303,7 +303,24 @@ mpc_sin_cos (mpc_ptr rop_sin, mpc_ptr rop_cos, mpc_srcptr op, prec = 2; if (rop_sin != NULL) - prec = MPC_MAX (prec, MPC_MAX_PREC (rop_sin)); + { + mp_prec_t er, ei; + prec = MPC_MAX (prec, MPC_MAX_PREC (rop_sin)); + /* since the Taylor expansion of sin(x) at x=0 is x - x^3/6 + O(x^5), + if x <= 2^(-p), then the second term/x is about 2^(-2p)/6, thus we + need at least 2p+3 bits of precision. This is true only when x is + exactly representable in the target precision. */ + if (MPC_MAX_PREC (op) <= prec) + { + er = mpfr_get_exp (mpc_realref (op)); + ei = mpfr_get_exp (mpc_imagref (op)); + /* consider the maximal exponent only */ + er = (er < ei) ? ei : er; + if (er < 0) + if (prec < 2 * (mp_prec_t) (-er) + 3) + prec = 2 * (mp_prec_t) (-er) + 3; + } + } if (rop_cos != NULL) prec = MPC_MAX (prec, MPC_MAX_PREC (rop_cos)); |