[Gmp-commit] /var/hg/gmp-proj/mini-gmp: Added tests for mpz_lcm.

mercurial at gmplib.org mercurial at gmplib.org
Thu Jan 12 10:11:56 CET 2012


details:   /var/hg/gmp-proj/mini-gmp/rev/922ff255e570
changeset: 70:922ff255e570
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Thu Jan 12 10:11:54 2012 +0100
description:
Added tests for mpz_lcm.

diffstat:

 mini-gmp.h         |   2 ++
 tests/Makefile     |   4 ++--
 tests/hex-random.c |  11 +++++++++++
 tests/hex-random.h |   2 +-
 4 files changed, 16 insertions(+), 3 deletions(-)

diffs (66 lines):

diff -r a861f07d4d31 -r 922ff255e570 mini-gmp.h
--- a/mini-gmp.h	Thu Jan 12 09:29:17 2012 +0100
+++ b/mini-gmp.h	Thu Jan 12 10:11:54 2012 +0100
@@ -142,6 +142,8 @@
 unsigned long mpz_gcd_ui (mpz_t, const mpz_t, unsigned long);
 void mpz_gcd (mpz_t, const mpz_t, const mpz_t);
 void mpz_gcdext (mpz_t, mpz_t, mpz_t, const mpz_t, const mpz_t);
+void mpz_lcm_ui (mpz_t, const mpz_t, unsigned long);
+void mpz_lcm (mpz_t, const mpz_t, const mpz_t);
 int mpz_invert (mpz_t, const mpz_t, const mpz_t);
 
 void mpz_sqrtrem (mpz_t, mpz_t, const mpz_t);
diff -r a861f07d4d31 -r 922ff255e570 tests/Makefile
--- a/tests/Makefile	Thu Jan 12 09:29:17 2012 +0100
+++ b/tests/Makefile	Thu Jan 12 10:11:54 2012 +0100
@@ -8,7 +8,7 @@
 LIBS = -lgmp -lm -lmcheck
 
 CHECK_PROGRAMS = t-add t-sub t-mul t-invert t-div t-double t-gcd \
-	t-sqrt t-powm t-logops t-str 
+	t-sqrt t-powm t-logops t-str t-lcm 
 
 MISC_OBJS = hex-random.o mini-random.o mini-gmp.o
 
@@ -33,7 +33,7 @@
 	$(CC) $(LDFLAGS) $^ $(LIBS) -o $@
 
 # Missing tests include:
-#   mpz_cmp_d, mpz_popcount, mpz_hamdist, mpz_ui_pow_ui, mpz_lcm
+#   mpz_cmp_d, mpz_popcount, mpz_hamdist, mpz_ui_pow_ui
 
 check: $(CHECK_PROGRAMS)
 	./run-tests $(CHECK_PROGRAMS)
diff -r a861f07d4d31 -r 922ff255e570 tests/hex-random.c
--- a/tests/hex-random.c	Thu Jan 12 09:29:17 2012 +0100
+++ b/tests/hex-random.c	Thu Jan 12 10:11:54 2012 +0100
@@ -128,6 +128,17 @@
 	}
       mpz_gcd (r, a, b);
       break;
+    case OP_LCM:
+      if (signs & 4)
+	{
+	  /* Produce a large gcd */
+	  unsigned long gbits = gmp_urandomb_ui (state, 32) % maxbits;
+	  mpz_rrandomb (r, state, gbits);
+	  mpz_mul (a, a, r);
+	  mpz_mul (b, b, r);
+	}
+      mpz_lcm (r, a, b);
+      break;
     case OP_AND:
       mpz_and (r, a, b);
       break;
diff -r a861f07d4d31 -r 922ff255e570 tests/hex-random.h
--- a/tests/hex-random.h	Thu Jan 12 09:29:17 2012 +0100
+++ b/tests/hex-random.h	Thu Jan 12 10:11:54 2012 +0100
@@ -18,7 +18,7 @@
 along with the GNU MP Library.  If not, see http://www.gnu.org/licenses/.  */
 
 enum hex_random_op { OP_ADD, OP_SUB, OP_MUL, OP_CDIV, OP_FDIV, OP_TDIV,
-		     OP_GCD, OP_POWM, OP_AND, OP_IOR, OP_XOR };
+		     OP_GCD, OP_LCM, OP_POWM, OP_AND, OP_IOR, OP_XOR };
 
 void hex_random_init (void);
 char *hex_urandomb (unsigned long bits);


More information about the gmp-commit mailing list