summaryrefslogtreecommitdiff
path: root/tests/tset_ld.c
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2016-09-12 10:05:12 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2016-09-12 10:05:12 +0000
commit1885b4db27e4e306cbaa0356f88aa95e71ed0e92 (patch)
tree8a6246736595c33f851ab8a4f97539ec55550da9 /tests/tset_ld.c
parent61d0e3d0f65a621ad4abc56c75f7ecf306953cd6 (diff)
downloadmpfr-1885b4db27e4e306cbaa0356f88aa95e71ed0e92.tar.gz
[tests/tset_ld.c] Fixed print_binary (and no longer any failure with
gcc -mpc64 on x86). git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@10850 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests/tset_ld.c')
-rw-r--r--tests/tset_ld.c33
1 files changed, 15 insertions, 18 deletions
diff --git a/tests/tset_ld.c b/tests/tset_ld.c
index 47b35686a..7d50d274a 100644
--- a/tests/tset_ld.c
+++ b/tests/tset_ld.c
@@ -129,28 +129,25 @@ print_binary (long double d, int flag)
half the precision of d, since otherwise d-f might not be exact.
This method does not work with flush-to-zero on underflow. */
f = 0.0; /* will hold accumulated powers of 2 */
- r = d; /* invariant: r = d - f */
- while (r > (long double) 0.0)
+ while (1)
{
prec++;
- if (r >= e)
+ r = f + e;
+ /* r is close to f (in particular in the cases where f+e may
+ not be exact), so that r - f should be exact. */
+ if (r - f != e) /* f+e is not exact */
+ {
+ d -= f; /* should be exact */
+ f = 0.0;
+ r = e;
+ }
+ if (d >= r)
{
- volatile long double g;
if (flag == 1)
printf ("1");
- g = f + e;
- /* g is close to f (in particular in the cases where f+e may
- not be exact), so that g - f should be exact. */
- if (g - f != e) /* f+e is not exact */
- {
- r = d = d - f; /* should be exact */
- f = 0.0;
- }
- f = f + e;
- /* FIXME: d - f may not be exact, so that the r >= e test in
- the next iteration may be wrong. Example: 2^56-2^54-1 is
- output as "0.11e56". */
- r = d - f;
+ if (d == r)
+ break;
+ f = r;
}
else
{
@@ -159,7 +156,7 @@ print_binary (long double d, int flag)
}
e *= (long double) 0.5;
/* The following assertion may fail with flush-to-zero on underflow. */
- MPFR_ASSERTN (r == 0 || e != 0);
+ MPFR_ASSERTN (e != 0);
if (flag == 2) printf ("4: d=%.36Le e=%.36Le prec=%ld\n", d, e,
(long) prec);
}