/src/numtheory/fp_lcm.c

http://github.com/libtom/tomsfastmath · C · 20 lines · 15 code · 2 blank · 3 comment · 3 complexity · 467f4f0348ac56b5fd4b88e9b865c58f MD5 · raw file

  1. /* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
  2. /* SPDX-License-Identifier: Unlicense */
  3. #include <tfm_private.h>
  4. /* c = [a, b] */
  5. void fp_lcm(fp_int *a, fp_int *b, fp_int *c)
  6. {
  7. fp_int t1, t2;
  8. fp_init(&t1);
  9. fp_init(&t2);
  10. fp_gcd(a, b, &t1);
  11. if (fp_cmp_mag(a, b) == FP_GT) {
  12. fp_div(a, &t1, &t2, NULL);
  13. fp_mul(b, &t2, c);
  14. } else {
  15. fp_div(b, &t1, &t2, NULL);
  16. fp_mul(a, &t2, c);
  17. }
  18. }