File:  [MW Coherent from dump] / coherent / d / usr / lib / libmp / gcd.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Wed May 29 04:56:38 2019 UTC (7 years, 2 months ago) by root
Branches: MarkWilliams, MAIN
CVS tags: relic, HEAD
coherent

#include "mprec.h"


/*
 *	Gcd sets the value of the mint pointed to by "c" to the greatest
 *	common divisor of the mints pointed to by "a" and "b".  Note that
 *	no assumption made on the distinctness of "a", "b" and "c".
 */

void
gcd(a, b, c)
register mint *a, *b, *c;
{
	register mint	*temp;
	mint	al, bl, quot;

	/* make local copyies of arguments */
	minit(&al);
	mcopy(a, &al);
	a = &al;
	minit(&bl);
	mcopy(b, &bl);
	b = &bl;

	/* calculate gcd by Euclidean algorithm */
	minit(&quot);
	while (!zerop(b)) {
		mdiv(a, b, &quot, a);
		temp = a;
		a = b;
		b = temp;
	}

	/* throw away garbage and return result */
	mpfree(quot.val);
	mpfree(b->val);
	mpfree(c->val);
	*c = *a;
}

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.