[Gmp-commit] /var/hg/gmp-proj/mini-gmp: Implemented mpz_lcm and mpz_lcm_ui.
mercurial at gmplib.org
mercurial at gmplib.org
Thu Jan 12 09:29:24 CET 2012
details: /var/hg/gmp-proj/mini-gmp/rev/a861f07d4d31
changeset: 69:a861f07d4d31
user: Marco Bodrato <bodrato at mail.dm.unipi.it>
date: Thu Jan 12 09:29:17 2012 +0100
description:
Implemented mpz_lcm and mpz_lcm_ui.
diffstat:
mini-gmp.c | 38 ++++++++++++++++++++++++++++++++++++--
tests/Makefile | 2 +-
2 files changed, 37 insertions(+), 3 deletions(-)
diffs (67 lines):
diff -r c3896920ac38 -r a861f07d4d31 mini-gmp.c
--- a/mini-gmp.c Thu Jan 12 09:08:27 2012 +0100
+++ b/mini-gmp.c Thu Jan 12 09:29:17 2012 +0100
@@ -40,8 +40,6 @@
mpz_fdiv_q_2exp
mpz_fdiv_r_2exp
mpz_import
- mpz_lcm
- mpz_lcm_ui
mpz_scan0
mpz_scan1.
*/
@@ -2662,6 +2660,42 @@
mpz_clear (t1);
}
+void
+mpz_lcm (mpz_t r, const mpz_t u, const mpz_t v)
+{
+ mpz_t g;
+
+ if (u->_mp_size == 0 || v->_mp_size == 0)
+ {
+ r->_mp_size = 0;
+ return;
+ }
+
+ mpz_init (g);
+
+ mpz_gcd (g, u, v);
+ mpz_divexact (g, u, g);
+ mpz_mul (r, g, v);
+
+ mpz_clear (g);
+ mpz_abs (r, r);
+}
+
+void
+mpz_lcm_ui (mpz_t r, const mpz_t u, unsigned long v)
+{
+ if (v == 0 || u->_mp_size == 0)
+ {
+ r->_mp_size = 0;
+ return;
+ }
+
+ v /= mpz_gcd_ui (NULL, u, v);
+ mpz_mul_ui (r, u, v);
+
+ mpz_abs (r, r);
+}
+
int
mpz_invert (mpz_t r, const mpz_t u, const mpz_t m)
{
diff -r c3896920ac38 -r a861f07d4d31 tests/Makefile
--- a/tests/Makefile Thu Jan 12 09:08:27 2012 +0100
+++ b/tests/Makefile Thu Jan 12 09:29:17 2012 +0100
@@ -33,7 +33,7 @@
$(CC) $(LDFLAGS) $^ $(LIBS) -o $@
# Missing tests include:
-# mpz_cmp_d, mpz_popcount, mpz_hamdist, mpz_ui_pow_ui
+# mpz_cmp_d, mpz_popcount, mpz_hamdist, mpz_ui_pow_ui, mpz_lcm
check: $(CHECK_PROGRAMS)
./run-tests $(CHECK_PROGRAMS)
More information about the gmp-commit
mailing list