summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2016-02-22 14:46:51 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2016-02-22 14:46:51 +0000
commit2fca7b6a41ae4c94cc1fc888057c037222a927c4 (patch)
treea53b716fedcaa2e6ca88257bb718499be0350689 /tests
parent06d455fd9d4aafc5c9784c0c23da27365e72ab68 (diff)
downloadmpfr-2fca7b6a41ae4c94cc1fc888057c037222a927c4.tar.gz
[src/sum.c] Fixed bugs in mpfr_sum, which could return wrong results
when not all the numbers have the same precision. A side effect is that this can make mpfr_sum much slower and/or take much more memory in some of such cases with the same program; this is normal and cannot easily be avoided with the current algorithm. Note: The full rewrite currently in the trunk has not been merged because this would not be a simple patch (and it is still incomplete when a number is reused as the output). [src/mpfr-impl.h] Updated the prototype of mpfr_sum_sort. Note: Since this function is used only internally and by the tests, this does not break the ABI. However the old and new tsum tests are source & binary incompatible. [tests/tsum.c] Updated the use of mpfr_sum_sort. Added a testcase. (merged changesets r8697,8699,8701,8851 from the trunk) git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/branches/3.1@10083 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests')
-rw-r--r--tests/tsum.c39
1 files changed, 38 insertions, 1 deletions
diff --git a/tests/tsum.c b/tests/tsum.c
index 5d9c8b598..38ebf52e3 100644
--- a/tests/tsum.c
+++ b/tests/tsum.c
@@ -126,6 +126,7 @@ test_sort (mpfr_prec_t f, unsigned long n)
mpfr_ptr *tabtmp;
mpfr_srcptr *perm;
unsigned long i;
+ mpfr_prec_t prec = MPFR_PREC_MIN;
/* Init stuff */
tab = (mpfr_t *) (*__gmp_allocate_func) (n * sizeof (mpfr_t));
@@ -140,7 +141,7 @@ test_sort (mpfr_prec_t f, unsigned long n)
tabtmp[i] = tab[i];
}
- mpfr_sum_sort ((mpfr_srcptr *)tabtmp, n, perm);
+ mpfr_sum_sort ((mpfr_srcptr *)tabtmp, n, perm, &prec);
if (check_is_sorted (n, perm) == 0)
{
@@ -300,6 +301,41 @@ void check_special (void)
mpfr_clears (tab[0], tab[1], tab[2], r, (mpfr_ptr) 0);
}
+/* bug reported by Joseph S. Myers on 2013-10-27
+ https://sympa.inria.fr/sympa/arc/mpfr/2013-10/msg00015.html */
+static void
+bug20131027 (void)
+{
+ mpfr_t r, t[4];
+ mpfr_ptr p[4];
+ char *s[4] = {
+ "0x1p1000",
+ "-0x0.fffffffffffff80000000000000001p1000",
+ "-0x1p947",
+ "0x1p880"
+ };
+ int i;
+
+ mpfr_init2 (r, 53);
+ for (i = 0; i < 4; i++)
+ {
+ mpfr_init2 (t[i], i == 0 ? 53 : 1000);
+ mpfr_set_str (t[i], s[i], 0, MPFR_RNDN);
+ p[i] = t[i];
+ }
+ mpfr_sum (r, p, 4, MPFR_RNDN);
+
+ if (MPFR_NOTZERO (r))
+ {
+ printf ("mpfr_sum incorrect in bug20131027: expected 0, got\n");
+ mpfr_dump (r);
+ exit (1);
+ }
+
+ for (i = 0; i < 4; i++)
+ mpfr_clear (t[i]);
+ mpfr_clear (r);
+}
int
main (void)
@@ -310,6 +346,7 @@ main (void)
tests_start_mpfr ();
check_special ();
+ bug20131027 ();
test_sort (1764, 1026);
for (p = 2 ; p < 444 ; p += 17)
for (n = 2 ; n < 1026 ; n += 42 + p)