summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--get_d.c6
-rw-r--r--mpfr-impl.h2
-rw-r--r--set_d.c8
-rw-r--r--tests/tcmp2.c4
-rw-r--r--tests/tout_str.c2
-rw-r--r--tests/tset_ld.c12
6 files changed, 13 insertions, 21 deletions
diff --git a/get_d.c b/get_d.c
index 754d6d647..4d8a43a2c 100644
--- a/get_d.c
+++ b/get_d.c
@@ -167,7 +167,7 @@ mpfr_get_d (mpfr_srcptr src, mp_rnd_t rnd_mode)
return negative ? MPFR_DBL_INFM : MPFR_DBL_INFP;
MPFR_ASSERTD (MPFR_IS_ZERO(src));
- return negative ? -0.0 : 0.0;
+ return negative ? DBL_NEG_ZERO : 0.0;
}
e = MPFR_GET_EXP (src);
@@ -183,7 +183,7 @@ mpfr_get_d (mpfr_srcptr src, mp_rnd_t rnd_mode)
d = negative ?
(rnd_mode == GMP_RNDD ||
(rnd_mode == GMP_RNDN && mpfr_cmp_si_2exp(src, -1, -1075) < 0)
- ? -DBL_MIN : -0.0) :
+ ? -DBL_MIN : DBL_NEG_ZERO) :
(rnd_mode == GMP_RNDU ||
(rnd_mode == GMP_RNDN && mpfr_cmp_si_2exp(src, 1, -1075) > 0)
? DBL_MIN : 0.0);
@@ -261,7 +261,7 @@ mpfr_get_d_2exp (long *expptr, mpfr_srcptr src, mp_rnd_t rnd_mode)
if (MPFR_IS_INF (src))
return negative ? MPFR_DBL_INFM : MPFR_DBL_INFP;
MPFR_ASSERTD (MPFR_IS_ZERO(src));
- return negative ? -0.0 : 0.0;
+ return negative ? DBL_NEG_ZERO : 0.0;
}
tmp[0] = *src; /* Hack copy mpfr_t */
diff --git a/mpfr-impl.h b/mpfr-impl.h
index 31d0d8a1a..a615e7ca8 100644
--- a/mpfr-impl.h
+++ b/mpfr-impl.h
@@ -334,10 +334,12 @@ static double double_zero = 0.0;
# define DBL_NAN (double_zero/double_zero)
# define DBL_POS_INF ((double) 1.0/double_zero)
# define DBL_NEG_INF ((double)-1.0/double_zero)
+# define DBL_NEG_ZERO (-double_zero)
#else
# define DBL_POS_INF ((double) 1.0/0.0)
# define DBL_NEG_INF ((double)-1.0/0.0)
# define DBL_NAN ((double) 0.0/0.0)
+# define DBL_NEG_ZERO (-0.0)
#endif
/* for x of type ieee_double_extract */
diff --git a/set_d.c b/set_d.c
index fec7356c0..813a1e2d2 100644
--- a/set_d.c
+++ b/set_d.c
@@ -176,11 +176,9 @@ mpfr_set_d (mpfr_ptr r, double d, mp_rnd_t rnd_mode)
We can't use d==+0.0 since it should be always true,
so we check that the memory representation of d is the
same than +0.0. etc */
-#ifdef _MSC_VER
- double poszero = +0.0, negzero = _chgsign (0.0);
-#else
- double poszero = +0.0, negzero = -0.0;
-#endif
+ /* FIXME: consider the case where +0.0 or -0.0 may have several
+ representations. */
+ double poszero = +0.0, negzero = DBL_NEG_ZERO;
if (memcmp(&d, &poszero, sizeof(double)) == 0)
MPFR_SET_POS(r);
else if (memcmp(&d, &negzero, sizeof(double)) == 0)
diff --git a/tests/tcmp2.c b/tests/tcmp2.c
index e01ba1f54..b490c17de 100644
--- a/tests/tcmp2.c
+++ b/tests/tcmp2.c
@@ -322,9 +322,9 @@ main (void)
x = y;
y = z;
}
- if (y != 0.0 && y != -0.0)
+ if (y != 0.0)
tcmp2 (x, y, -1);
- }
+ }
tests_end_mpfr ();
diff --git a/tests/tout_str.c b/tests/tout_str.c
index a1a445d90..dd8c64eb8 100644
--- a/tests/tout_str.c
+++ b/tests/tout_str.c
@@ -160,7 +160,7 @@ main (int argc, char *argv[])
check (-1.37247529013405550000e+15, GMP_RNDN, 7);
check (-1.5674376729569697500e+15, GMP_RNDN, 19);
check (-5.71262771772792640000e-79, GMP_RNDU, 16);
- check (-0.0, GMP_RNDU, 7);
+ check (DBL_NEG_ZERO, GMP_RNDU, 7);
check (-4.5306392613572974756e-308, GMP_RNDN, 8);
check (-6.7265890111403371523e-165, GMP_RNDN, 4);
check (-1.3242553591261807653e+156, GMP_RNDN, 16);
diff --git a/tests/tset_ld.c b/tests/tset_ld.c
index 317e62e30..d6606aca3 100644
--- a/tests/tset_ld.c
+++ b/tests/tset_ld.c
@@ -161,19 +161,11 @@ main (int argc, char *argv[])
/* check +0.0 and -0.0 */
d = 0.0;
check_set_get (d, x);
-#ifdef _MSC_VER
- d = _chgsign (0.0);
-#else
- d = -0.0;
-#endif
+ d = DBL_NEG_ZERO;
check_set_get (d, x);
/* checks that sign of -0.0 is set */
-#ifdef _MSC_VER
- mpfr_set_ld (x, _chgsign (0.0), GMP_RNDN);
-#else
- mpfr_set_ld (x, -0.0, GMP_RNDN);
-#endif
+ mpfr_set_ld (x, DBL_NEG_ZERO, GMP_RNDN);
if (MPFR_SIGN(x) > 0)
{
printf ("Error: sign of -0.0 is not set correctly\n");