diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2007-06-28 22:27:09 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2007-06-28 22:27:09 +0000 |
commit | 2c6e88aa658d31ef9f837404e98e59553528d586 (patch) | |
tree | 55f71b306c070d8c7f7fbd368e7b2203f1be64e4 /acos.c | |
parent | 38a802483d11676936b4f5362de84598716010b0 (diff) | |
download | mpfr-2c6e88aa658d31ef9f837404e98e59553528d586.tar.gz |
acos.c: fixed integer overflows; to avoid undefined behavior, I had
to add an assertion that is not always satisfied (the code needs to
be rewritten to take tiny arguments into account).
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@4580 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'acos.c')
-rw-r--r-- | acos.c | 10 |
1 files changed, 7 insertions, 3 deletions
@@ -91,9 +91,13 @@ mpfr_acos (mpfr_ptr acos, mpfr_srcptr x, mp_rnd_t rnd_mode) /* If x ~ 2^-N, acos(x) ~ PI/2 - x - x^3/6 If Prec < 2*N, we can't round since x^3/6 won't be counted. */ - if (MPFR_PREC (acos) >= MPFR_PREC (x) - && (mp_exp_t) prec <= -2*MPFR_GET_EXP (x) + 5) - prec = (mpfr_uexp_t) (-2*MPFR_GET_EXP (x)) + 5; + if (MPFR_PREC (acos) >= MPFR_PREC (x) && MPFR_GET_EXP (x) < 0) + { + mpfr_uexp_t pmin = (mpfr_uexp_t) (-2 * MPFR_GET_EXP (x)) + 5; + MPFR_ASSERTN (pmin <= MPFR_PREC_MAX); + if (prec < pmin) + prec = pmin; + } mpfr_init2 (tmp, prec); mpfr_init2 (arcc, prec); |