[Gmp-commit] /var/hg/gmp: 2 new changesets
mercurial at gmplib.org
mercurial at gmplib.org
Sun Jan 13 19:19:40 CET 2013
details: /var/hg/gmp/rev/6ae7d4a79886
changeset: 15265:6ae7d4a79886
user: Marco Bodrato <bodrato at mail.dm.unipi.it>
date: Sun Jan 13 19:13:22 2013 +0100
description:
mini-gmp/mini-gmp.c (mpz_fits_slong_p): Correct range.
details: /var/hg/gmp/rev/e1a986a1e808
changeset: 15266:e1a986a1e808
user: Marco Bodrato <bodrato at mail.dm.unipi.it>
date: Sun Jan 13 19:18:55 2013 +0100
description:
mini-gmp/tests/t-signed.c: New test program.
diffstat:
ChangeLog | 4 +
mini-gmp/mini-gmp.c | 4 +-
mini-gmp/tests/Makefile | 2 +-
mini-gmp/tests/t-signed.c | 129 ++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 136 insertions(+), 3 deletions(-)
diffs (174 lines):
diff -r 1c86d84a3c18 -r e1a986a1e808 ChangeLog
--- a/ChangeLog Sun Jan 13 10:50:16 2013 +0100
+++ b/ChangeLog Sun Jan 13 19:18:55 2013 +0100
@@ -18,6 +18,10 @@
* mini-gmp/tests/t-mul.c: Test also mpz_mul_si.
* mini-gmp/tests/t-sub.c: Test also mpz_ui_sub.
+ * mini-gmp/mini-gmp.c (mpz_fits_slong_p): Correct range.
+ * mini-gmp/tests/t-signed.c: New test program, for get/set/cmp_si.
+ * mini-gmp/tests/Makefile (CHECK_PROGRAMS): Added t-signed.
+
2013-01-10 Marco Bodrato <bodrato at mail.dm.unipi.it>
* mpz/export.c: Less restrictive ASSERTs.
diff -r 1c86d84a3c18 -r e1a986a1e808 mini-gmp/mini-gmp.c
--- a/mini-gmp/mini-gmp.c Sun Jan 13 10:50:16 2013 +0100
+++ b/mini-gmp/mini-gmp.c Sun Jan 13 19:18:55 2013 +0100
@@ -1410,9 +1410,9 @@
if (us == 0)
return 1;
else if (us == 1)
- return u->_mp_d[0] < (GMP_LIMB_HIGHBIT / 2);
+ return u->_mp_d[0] < GMP_LIMB_HIGHBIT;
else if (us == -1)
- return u->_mp_d[0] <= (GMP_LIMB_HIGHBIT / 2);
+ return u->_mp_d[0] <= GMP_LIMB_HIGHBIT;
else
return 0;
}
diff -r 1c86d84a3c18 -r e1a986a1e808 mini-gmp/tests/Makefile
--- a/mini-gmp/tests/Makefile Sun Jan 13 10:50:16 2013 +0100
+++ b/mini-gmp/tests/Makefile Sun Jan 13 19:18:55 2013 +0100
@@ -28,7 +28,7 @@
LIBS = -lgmp -lm -lmcheck
CHECK_PROGRAMS = t-add t-sub t-mul t-invert t-div t-div_2exp \
- t-double t-gcd t-lcm t-import t-comb \
+ t-double t-gcd t-lcm t-import t-comb t-signed \
t-sqrt t-root t-powm t-logops t-bitops t-scan t-str \
t-reuse
diff -r 1c86d84a3c18 -r e1a986a1e808 mini-gmp/tests/t-signed.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mini-gmp/tests/t-signed.c Sun Jan 13 19:18:55 2013 +0100
@@ -0,0 +1,129 @@
+/* Exercise some mpz_..._si functions.
+
+Copyright 2013 Free Software Foundation, Inc.
+
+This file is part of the GNU MP Library test suite.
+
+The GNU MP Library test suite is free software; you can redistribute it
+and/or modify it under the terms of the GNU General Public License as
+published by the Free Software Foundation; either version 3 of the License,
+or (at your option) any later version.
+
+The GNU MP Library test suite is distributed in the hope that it will be
+useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+Public License for more details.
+
+You should have received a copy of the GNU General Public License along with
+the GNU MP Library test suite. If not, see http://www.gnu.org/licenses/. */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "mini-gmp.h"
+
+void
+check_si (mpz_t sz, mpz_t oz, long si, int c)
+{
+ mpz_t t;
+ int fail;
+
+ mpz_init_set_si (t, si);
+
+ if ((fail = mpz_cmp_si (sz, si)) != 0)
+ printf ("mpz_cmp_si (sz, %ld) != 0.\n", si);
+ if (mpz_cmp_si (oz, si) != -c)
+ printf ("mpz_cmp_si (oz, %ld) != %i.\n", si, -c), fail = 1;
+ if (! mpz_fits_slong_p (sz))
+ printf ("mpz_fits_slong_p (sz) != 1.\n"), fail = 1;
+ if (mpz_get_si (sz) != si)
+ printf ("mpz_get_si (sz) != %ld.\n", si), fail = 1;
+ if (mpz_cmp (t, sz) != 0)
+ {
+ printf ("mpz_init_set_si (%ld) failed.\n", si);
+ printf (" got="); mpz_out_str (stdout, 10, t); printf ("\n");
+ fail = 1;
+ }
+
+ mpz_clear (t);
+
+ if (fail)
+ {
+ printf (" sz="); mpz_out_str (stdout, 10, sz); printf ("\n");
+ printf (" oz="); mpz_out_str (stdout, 10, oz); printf ("\n");
+ printf (" si=%ld\n", si);
+ abort ();
+ }
+}
+
+void
+try_op_si (int c)
+{
+ long si, oi;
+ mpz_t sz, oz;
+
+ si = c;
+ mpz_init_set_si (sz, si);
+
+ oi = si;
+ mpz_init_set (oz, sz);
+
+ do {
+ si *= 2;
+ mpz_mul_2exp (sz, sz, 1);
+
+ if (mpz_cmp_si (sz, oi) != c)
+ {
+ printf ("mpz_cmp_si (sz, %ld) != %i.\n", oi, c);
+ printf (" sz="); mpz_out_str (stdout, 10, sz); printf ("\n");
+ abort ();
+ }
+
+ if ((si < oi ? -1 : si > oi) != c)
+ break;
+
+ check_si (sz, oz, si, c);
+
+ oi = (si - c) * 2 + c;
+ mpz_mul_si (oz, sz, 2*c);
+ if (c == -1)
+ mpz_ui_sub (oz, 1, oz); /* oz = sz * 2 + 1 */
+ else
+ mpz_sub_ui (oz, oz, 1); /* oz = sz * 2 - 1 */
+
+ if (mpz_cmp_si (oz, si) != c)
+ {
+ printf ("mpz_cmp_si (oz, %ld) != %i.\n", si, c);
+ printf (" oz="); mpz_out_str (stdout, 10, oz); printf ("\n");
+ abort ();
+ }
+
+ if ((oi < si ? -1 : oi > si) != c)
+ {
+ mpz_set (sz, oz);
+ break;
+ }
+
+ check_si (oz, sz, oi, c);
+ } while (1);
+
+ mpz_clear (oz);
+
+ if (mpz_fits_slong_p (sz))
+ {
+ printf ("Should not fit a signed long any more.\n");
+ printf (" sz="); mpz_out_str (stdout, 10, sz); printf ("\n");
+ abort ();
+ }
+
+ mpz_clear (sz);
+}
+
+int
+main (int argc, char *argv[])
+{
+ try_op_si (-1);
+ try_op_si (1);
+
+ return 0;
+}
More information about the gmp-commit
mailing list