diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2016-09-12 09:40:34 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2016-09-12 09:40:34 +0000 |
commit | 854787984c814925d4b627f03f97af16a2015d5c (patch) | |
tree | e2526b91a033867af28c29e75de4c226c9d18414 /tests/tset_ld.c | |
parent | 29d84a76fec8deb9879b65625a9b31537a642e66 (diff) | |
download | mpfr-854787984c814925d4b627f03f97af16a2015d5c.tar.gz |
[tests/tset_ld.c] Fixed print_binary.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@10847 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests/tset_ld.c')
-rw-r--r-- | tests/tset_ld.c | 37 |
1 files changed, 16 insertions, 21 deletions
diff --git a/tests/tset_ld.c b/tests/tset_ld.c index 3eed409d4..38518959c 100644 --- a/tests/tset_ld.c +++ b/tests/tset_ld.c @@ -119,38 +119,33 @@ print_binary (long double d, int flag) printf ("0."); if (flag == 2) printf ("3: d=%.36Le e=%.36Le prec=%ld\n", d, e, (long) prec); - /* Note: the method we use here to extract the bits of r is the following, + /* Note: the method we use here to extract the bits of d is the following, to deal with the case where the rounding precision is less than the - precision of r: - (1) we accumulate the upper bits of r into f + precision of d: + (1) we accumulate the upper bits of d into f (2) when accumulating a new bit into f is not exact, we subtract - f from r and reset f to 0 + f from d and reset f to 0 This is guaranteed to work only when the rounding precision is at least - half the precision of r, since otherwise r-f might not be exact. + 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) { 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 */ { - volatile long double g; + d -= f; /* should be exact */ + f = 0.0; + r = e; + } + if (d >= r) + { + f = r; 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; } else { |