From e9ceabad932abe899aa321154b086591b715197d Mon Sep 17 00:00:00 2001 From: vlefevre Date: Sat, 29 Jan 2005 11:42:08 +0000 Subject: Fixed a sign bug in mpfr_exp (found by Mark J Watkins). git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/branches/mpfr-2-1-branch@3247 280ebfd0-de03-0410-8827-d642c229c3f4 --- exp.c | 4 ++-- tests/texp.c | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/exp.c b/exp.c index 4682896b8..56fbb9ce9 100644 --- a/exp.c +++ b/exp.c @@ -1,6 +1,6 @@ /* mpfr_exp -- exponential of a floating-point number -Copyright 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation. +Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation. Contributed by the Spaces project. This file is part of the MPFR Library. @@ -82,9 +82,9 @@ mpfr_exp (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode) { int signx = MPFR_SIGN(x); + MPFR_SET_POS(y); if (MPFR_IS_NEG_SIGN(signx) && (rnd_mode == GMP_RNDD)) { - MPFR_SET_POS(y); mpfr_setmax (y, 0); /* y = 1 - epsilon */ return -1; } diff --git a/tests/texp.c b/tests/texp.c index 0bd81ded1..3ff9acfae 100644 --- a/tests/texp.c +++ b/tests/texp.c @@ -31,6 +31,8 @@ check3 (const char *op, mp_rnd_t rnd, const char *res) mpfr_t x, y; mpfr_inits2 (53, x, y, NULL); + /* y negative. If we forget to set the sign in mpfr_exp, we'll see it. */ + mpfr_set_si (y, -1, GMP_RNDN); mpfr_set_str1 (x, op); mpfr_exp (y, x, rnd); if (mpfr_cmp_str1 (y, res) ) @@ -385,6 +387,8 @@ main (int argc, char *argv[]) compare_exp2_exp3(500); check_worst_cases(); check3("0.0", GMP_RNDU, "1.0"); + check3("-1e-170", GMP_RNDU, "1.0"); + check3("-1e-170", GMP_RNDN, "1.0"); check3("-8.88024741073346941839e-17", GMP_RNDU, "1.0"); check3("8.70772839244701057915e-01", GMP_RNDN, "2.38875626491680437269"); check3("1.0", GMP_RNDN, "2.71828182845904509080"); -- cgit v1.2.1