summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cos.c10
-rw-r--r--tests/tcos.c21
-rw-r--r--tests/tlog.c2
3 files changed, 30 insertions, 3 deletions
diff --git a/cos.c b/cos.c
index c0177d2ec..dd04f4af2 100644
--- a/cos.c
+++ b/cos.c
@@ -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"))