[Gmp-commit] /var/hg/gmp: 2 new changesets

mercurial at gmplib.org mercurial at gmplib.org
Thu May 17 13:07:46 CEST 2012


details:   /var/hg/gmp/rev/81b36dd999f8
changeset: 14975:81b36dd999f8
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Thu May 17 13:05:19 2012 +0200
description:
tests/mpf/t-set_ui.c (check_data): LONG_HIGHBIT -> ULONG_HIGHBIT.

details:   /var/hg/gmp/rev/ad63ba1421f3
changeset: 14976:ad63ba1421f3
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Thu May 17 13:07:32 2012 +0200
description:
tests/mpf/t-set.c (check_random): New check, both set and init_set.

diffstat:

 ChangeLog            |   3 ++
 tests/mpf/t-set.c    |  67 +++++++++++++++++++++++++++++++++++++++++++++++++--
 tests/mpf/t-set_ui.c |   2 +-
 3 files changed, 68 insertions(+), 4 deletions(-)

diffs (112 lines):

diff -r cd5ec2ff1103 -r ad63ba1421f3 ChangeLog
--- a/ChangeLog	Thu May 17 11:23:36 2012 +0200
+++ b/ChangeLog	Thu May 17 13:07:32 2012 +0200
@@ -3,6 +3,9 @@
 	* mpf/pow_ui.c: Simplify.
 	* tests/mpf/reuse.c (dsi_func): Exercise pow_ui.
 
+	* tests/mpf/t-set_ui.c (check_data): LONG_HIGHBIT -> ULONG_HIGHBIT.
+	* tests/mpf/t-set.c (check_random): New check, both set and init_set.
+
 2012-05-16  Torbjorn Granlund  <tege at gmplib.org>
 
 	* tests/mpf/t-eq.c (check_random): New function, meat from old main().
diff -r cd5ec2ff1103 -r ad63ba1421f3 tests/mpf/t-set.c
--- a/tests/mpf/t-set.c	Thu May 17 11:23:36 2012 +0200
+++ b/tests/mpf/t-set.c	Thu May 17 13:07:32 2012 +0200
@@ -1,6 +1,6 @@
-/* Test mpf_set.
+/* Test mpf_set, mpf_init_set.
 
-Copyright 2004 Free Software Foundation, Inc.
+Copyright 2004, 2012 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -40,12 +40,73 @@
   mpf_clear (f);
 }
 
+void
+check_random (long reps)
+{
+  unsigned long test;
+  gmp_randstate_ptr rands;
+  mpf_t a, b;
+  mpz_t z;
+  int precbits;
+
+#define PRECBITS 10
+
+  rands = RANDS;
+
+  mpz_init (z);
+  mpf_init2 (a, 1 << PRECBITS);
+
+  for (test = 0; test < reps; test++)
+    {
+      mpz_urandomb (z, rands, PRECBITS);
+      precbits = mpz_get_ui (z) + 1;
+      mpz_urandomb (z, rands, precbits);
+      mpz_setbit (z, precbits  - 1);	/* make sure msb is set */
+      mpf_set_z (a, z);
+      mpz_urandomb (z, rands, PRECBITS);
+      mpf_div_2exp (a, a, mpz_get_ui (z) + 1);
+      mpz_urandomb (z, rands, PRECBITS);
+      precbits -= mpz_get_ui (z);
+      if (precbits <= 0)
+	precbits = 1 - precbits;
+      mpf_set_default_prec (precbits);
+
+      mpf_init_set (b, a);
+      MPF_CHECK_FORMAT (b);
+      if (!mpf_eq (a, b, precbits))
+	{
+	  printf ("mpf_init_set wrong.\n");
+	  abort();
+	}
+
+      mpf_set_ui (b, 0);
+      mpf_set (b, a);
+      MPF_CHECK_FORMAT (b);
+      if (!mpf_eq (a, b, precbits))
+	{
+	  printf ("mpf_set wrong.\n");
+	  abort();
+	}
+
+      mpf_clear (b);
+    }
+
+  mpf_clear (a);
+  mpz_clear (z);
+}
+
 int
-main (void)
+main (int argc, char *argv[])
 {
+  long reps = 10000;
+
+  if (argc == 2)
+    reps = strtol (argv[1], 0, 0);
+
   tests_start ();
 
   check_reuse ();
+  check_random (reps);
 
   tests_end ();
   exit (0);
diff -r cd5ec2ff1103 -r ad63ba1421f3 tests/mpf/t-set_ui.c
--- a/tests/mpf/t-set_ui.c	Thu May 17 11:23:36 2012 +0200
+++ b/tests/mpf/t-set_ui.c	Thu May 17 13:07:32 2012 +0200
@@ -41,7 +41,7 @@
 #else
     { ULONG_MAX,     2, { ULONG_MAX & GMP_NUMB_MASK,
                           ULONG_MAX >> GMP_NUMB_BITS } },
-    { LONG_HIGHBIT,  2, { 0,
+    { ULONG_HIGHBIT, 2, { 0,
                           ULONG_HIGHBIT >> GMP_NUMB_BITS } },
 #endif
   };


More information about the gmp-commit mailing list