summaryrefslogtreecommitdiff
path: root/sub.c
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2003-05-22 21:39:40 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2003-05-22 21:39:40 +0000
commit44b4dd94bb98c8d9e7850ae401232bd1b2ea3028 (patch)
tree9670f0ef8017d42ad2a2062dc08c63c022e450c8 /sub.c
parent2f3cb289a102043a22bd32c5950db37199fb3fd2 (diff)
downloadmpfr-44b4dd94bb98c8d9e7850ae401232bd1b2ea3028.tar.gz
Macros MPFR_EXP_INVALID (invalid exponent value) and MPFR_EXP_CHECK
added. Code update to use MPFR_GET_EXP and MPFR_SET_EXP instead of MPFR_EXP to allow more bug detection related to special values. Macros MPFR_SET_NAN, MPFR_SET_INF, MPFR_SET_ZERO and MPFR_INIT set the exponent of the number to MPFR_EXP_INVALID if MPFR_EXP_CHECK is defined. Compile with -DMPFR_EXP_CHECK and make check to see the potential problems; currently, 40 of 76 tests fail. git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@2301 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'sub.c')
-rw-r--r--sub.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/sub.c b/sub.c
index 37689c65f..bdf3b3c20 100644
--- a/sub.c
+++ b/sub.c
@@ -1,6 +1,6 @@
/* mpfr_sub -- subtract two floating-point numbers
-Copyright 2001, 2002 Free Software Foundation.
+Copyright 2001, 2002, 2003 Free Software Foundation.
Contributed by the Spaces project, INRIA Lorraine.
This file is part of the MPFR Library.
@@ -90,22 +90,23 @@ mpfr_sub (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode)
}
else
{ /* signs differ, it's an addition */
- if (MPFR_EXP(b) < MPFR_EXP(c))
+ mp_exp_t eb, ec;
+ eb = MPFR_GET_EXP (b);
+ ec = MPFR_GET_EXP (c);
+ if (eb < ec)
{ /* exchange rounding modes towards +/- infinity */
int inexact;
if (rnd_mode == GMP_RNDU)
rnd_mode = GMP_RNDD;
else if (rnd_mode == GMP_RNDD)
rnd_mode = GMP_RNDU;
- inexact = mpfr_add1(a, c, b, rnd_mode,
- (mp_exp_unsigned_t) MPFR_EXP(c) - MPFR_EXP(b));
+ inexact = mpfr_add1(a, c, b, rnd_mode, (mp_exp_unsigned_t) ec - eb);
MPFR_CHANGE_SIGN(a);
return -inexact;
}
else
{
- return mpfr_add1(a, b, c, rnd_mode,
- (mp_exp_unsigned_t) MPFR_EXP(b) - MPFR_EXP(c));
+ return mpfr_add1(a, b, c, rnd_mode, (mp_exp_unsigned_t) eb - ec);
}
}
}