summaryrefslogtreecommitdiff
path: root/mpz/lcm.c
diff options
context:
space:
mode:
authortege <tege@gmplib.org>1996-10-18 10:47:25 +0200
committertege <tege@gmplib.org>1996-10-18 10:47:25 +0200
commitc3d4e596048c8f43d0d5bfcaad3d88b4d3cbe8b4 (patch)
tree40a24bf942a84a35472adba59b125a3d5e29ee1d /mpz/lcm.c
parente83917533027ee4c95c136ee329b75aace39cf4f (diff)
downloadgmp-c3d4e596048c8f43d0d5bfcaad3d88b4d3cbe8b4.tar.gz
New file.
Diffstat (limited to 'mpz/lcm.c')
-rw-r--r--mpz/lcm.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/mpz/lcm.c b/mpz/lcm.c
new file mode 100644
index 000000000..22f3a83de
--- /dev/null
+++ b/mpz/lcm.c
@@ -0,0 +1,56 @@
+/* mpz/lcm.c: Calculate the least common multiple of two integers.
+
+Copyright (C) 1996 Free Software Foundation, Inc.
+
+This file is part of the GNU MP Library.
+
+The GNU MP Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Library General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at your
+option) any later version.
+
+The GNU MP Library 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 Library General Public
+License for more details.
+
+You should have received a copy of the GNU Library General Public License
+along with the GNU MP Library; see the file COPYING.LIB. If not, write to
+the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+MA 02111-1307, USA. */
+
+#include "gmp.h"
+#include "gmp-impl.h"
+#include "longlong.h"
+
+void *_mpz_realloc ();
+
+void
+#if __STDC__
+mpz_lcm (mpz_ptr r, mpz_srcptr u, mpz_srcptr v)
+#else
+mpz_lcm (r, u, v)
+ mpz_ptr r;
+ mpz_srcptr u;
+ mpz_srcptr v;
+#endif
+{
+ mpz_t g;
+ mp_size_t usize, vsize, size;
+
+ usize = ABS (SIZ (u));
+ vsize = ABS (SIZ (v));
+
+ if (usize == 0 || vsize == 0)
+ {
+ SIZ (r) = 0;
+ return;
+ }
+
+ size = MAX (usize, vsize);
+ MPZ_TMP_INIT (g, size);
+
+ mpz_gcd (g, u, v);
+ mpz_divexact (g, u, g);
+ mpz_mul (r, g, v);
+}