summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2003-10-16 09:55:46 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2003-10-16 09:55:46 +0000
commit7f857964d869e4a3f316a7da845e11a9da0388a5 (patch)
treec6324c9251f6d5080b8927e6121b27c64fb5f708
parent9ff0c4e04d3d5ef8057cb3c0b70e28938e5fa882 (diff)
downloadmpfr-7f857964d869e4a3f316a7da845e11a9da0388a5.tar.gz
Fixed several bugs.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@2502 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r--get_d.c26
-rw-r--r--set_d.c28
2 files changed, 25 insertions, 29 deletions
diff --git a/get_d.c b/get_d.c
index cf02cae7d..85590c0bb 100644
--- a/get_d.c
+++ b/get_d.c
@@ -45,6 +45,7 @@ MA 02111-1307, USA. */
compiler+system was seen incorrectly converting from a "float" NaN. */
#if _GMP_IEEE_FLOATS
+
/* The "d" field guarantees alignment to a suitable boundary for a double.
Could use a union instead, if we checked the compiler supports union
initializers. */
@@ -72,7 +73,14 @@ static const struct dbl_bytes dbl_infp = { { 0x7F, 0xF0, 0, 0, 0, 0, 0, 0 } };
static const struct dbl_bytes dbl_infm = { { 0xFF, 0xF0, 0, 0, 0, 0, 0, 0 } };
static const struct dbl_bytes dbl_nan = { { 0x7F, 0xF8, 0, 0, 0, 0, 0, 0 } };
#endif
-#endif
+
+#else /* _GMP_IEEE_FLOATS */
+
+#define MPFR_DBL_INFP DBL_POS_INF
+#define MPFR_DBL_INFM DBL_NEG_INF
+#define MPFR_DBL_NAN DBL_NAN
+
+#endif /* _GMP_IEEE_FLOATS */
/* multiplies 1/2 <= d <= 1 by 2^exp */
@@ -142,24 +150,12 @@ mpfr_get_d3 (mpfr_srcptr src, mp_exp_t e, mp_rnd_t rnd_mode)
int negative;
if (MPFR_IS_NAN(src))
- {
-#ifdef MPFR_DBL_NAN
- return MPFR_DBL_NAN;
-#else
- DIVIDE_BY_ZERO;
-#endif
- }
+ return MPFR_DBL_NAN;
negative = MPFR_SIGN(src) < 0;
if (MPFR_IS_INF(src))
- {
-#ifdef MPFR_DBL_INFP
- return negative ? MPFR_DBL_INFM : MPFR_DBL_INFP;
-#else
- DIVIDE_BY_ZERO;
-#endif
- }
+ return negative ? MPFR_DBL_INFM : MPFR_DBL_INFP;
if (MPFR_IS_ZERO(src))
return negative ? -0.0 : 0.0;
diff --git a/set_d.c b/set_d.c
index a98256d3c..a6fa6bf42 100644
--- a/set_d.c
+++ b/set_d.c
@@ -30,12 +30,10 @@ MA 02111-1307, USA. */
#define MPFR_LIMBS_PER_DOUBLE 2
#elif (BITS_PER_MP_LIMB >= 64)
#define MPFR_LIMBS_PER_DOUBLE 1
-#elif (BITS_PER_MP_LIMB == 16)
-#define MPFR_LIMBS_PER_DOUBLE 4
+#else
+#error "Unsupported value of BITS_PER_MP_LIMB"
#endif
-static int __mpfr_extract_double _PROTO ((mp_ptr, double));
-
/* Included from gmp-2.0.2, patched to support denorms */
#ifdef XDEBUG
@@ -57,10 +55,9 @@ __mpfr_extract_double (mp_ptr rp, double d)
#endif
/* BUGS
-
1. Should handle Inf and NaN in IEEE specific code.
2. Handle Inf and NaN also in default code, to avoid hangs.
- 3. Generalize to handle all BITS_PER_MP_LIMB >= 32.
+ 3. Generalize to handle all BITS_PER_MP_LIMB.
4. This lits is incomplete and misspelled.
*/
@@ -71,6 +68,7 @@ __mpfr_extract_double (mp_ptr rp, double d)
}
#if _GMP_IEEE_FLOATS
+
{
union ieee_double_extract x;
x.d = d;
@@ -96,16 +94,21 @@ __mpfr_extract_double (mp_ptr rp, double d)
manl = x.s.manl << 11; /* low 21 bits */
#endif
}
+
+ if (exp)
+ exp -= 1022;
+ else
+ exp = -1021;
}
-#else
+
+#else /* _GMP_IEEE_FLOATS */
+
{
/* Unknown (or known to be non-IEEE) double format. */
exp = 0;
if (d >= 1.0)
{
- if (d * 0.5 == d)
- abort ();
-
+ MPFR_ASSERTN (d * 0.5 != d);
while (d >= 32768.0)
{
d *= (1.0 / 65536.0);
@@ -138,12 +141,9 @@ __mpfr_extract_double (mp_ptr rp, double d)
manh = d;
manl = (d - manh) * MP_BASE_AS_DOUBLE;
#endif
-
- exp += 1022;
}
-#endif
- if (exp) exp = (unsigned) exp - 1022; else exp = -1021;
+#endif /* _GMP_IEEE_FLOATS */
#if BITS_PER_MP_LIMB == 64
rp[0] = manl;