diff options
author | pelissip <pelissip@280ebfd0-de03-0410-8827-d642c229c3f4> | 2004-05-04 15:46:42 +0000 |
---|---|---|
committer | pelissip <pelissip@280ebfd0-de03-0410-8827-d642c229c3f4> | 2004-05-04 15:46:42 +0000 |
commit | c1e8d70fa718233a127753dfe3220ceb547a53df (patch) | |
tree | 6d96050240cebab2c1706a4686c65b4da91432e6 | |
parent | 6188785ed16425e8c3d9474098987af936bd9e8e (diff) | |
download | mpfr-c1e8d70fa718233a127753dfe3220ceb547a53df.tar.gz |
Fix a critical bug in cos in case you have set the float range for the exponents.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@2895 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r-- | cos.c | 10 | ||||
-rw-r--r-- | tests/tcos.c | 21 | ||||
-rw-r--r-- | tests/tlog.c | 2 |
3 files changed, 30 insertions, 3 deletions
@@ -19,6 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include <stdio.h> #include "mpfr-impl.h" static int mpfr_cos2_aux _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr)); @@ -43,6 +44,8 @@ mpfr_cos (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode) } } + mpfr_save_emin_emax (); + precy = MPFR_PREC(y); K0 = __gmpfr_isqrt(precy / 2); @@ -85,11 +88,12 @@ mpfr_cos (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode) mpfr_set_prec (s, m); } - inexact = mpfr_set (y, s, rnd_mode); + mpfr_restore_emin_emax (); + inexact = mpfr_set (y, s, rnd_mode); /* FIXME: Dont' need check range? */ mpfr_clear (r); mpfr_clear (s); - + return inexact; } @@ -105,7 +109,7 @@ mpfr_cos2_aux (mpfr_ptr s, mpfr_srcptr r) long int prec, m = MPFR_PREC(s); mpfr_t t; - MPFR_ASSERTD (MPFR_GET_EXP (r) <= 0); + MPFR_ASSERTN (MPFR_GET_EXP (r) <= 0); mpfr_init2 (t, m); mpfr_set_ui (t, 1, GMP_RNDN); diff --git a/tests/tcos.c b/tests/tcos.c index 9a72ec19a..a52160c61 100644 --- a/tests/tcos.c +++ b/tests/tcos.c @@ -99,6 +99,26 @@ check_nans (void) mpfr_clear (y); } +static void +special_overflow (void) +{ + mpfr_t x, y; + + mpfr_init2 (x, 24); + mpfr_init2 (y, 73); + + /* Check special case: An overflow in const_pi could occurs! */ + mpfr_set_emin (-125); + mpfr_set_emax (128); + mpfr_set_str_binary (x, "0.111101010110110011101101E6"); + mpfr_cos (y, x, GMP_RNDZ); + mpfr_set_emin (MPFR_EMIN_MIN); + mpfr_set_emax (MPFR_EMAX_MAX); + + mpfr_clear (x); + mpfr_clear (y); +} + int main (int argc, char *argv[]) { @@ -106,6 +126,7 @@ main (int argc, char *argv[]) tests_start_mpfr (); + special_overflow (); check_nans (); mpfr_init (x); diff --git a/tests/tlog.c b/tests/tlog.c index dbcede009..1ad90cf5f 100644 --- a/tests/tlog.c +++ b/tests/tlog.c @@ -168,6 +168,8 @@ special (void) mpfr_set_emin (MPFR_EMIN_MIN); mpfr_set_emax (MPFR_EMAX_MAX); + mpfr_set_prec (y, 53); + mpfr_set_prec (x, 53); mpfr_set_ui (x, 3, GMP_RNDD); mpfr_log (y, x, GMP_RNDD); if (mpfr_cmp_str1 (y, "1.09861228866810956")) |