DataMuseum.dk

Presents historical artifacts from the history of:

Commodore CBM-900

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about Commodore CBM-900

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download

⟦92f20cf1e⟧ TextFile

    Length: 686 (0x2ae)
    Types: TextFile
    Notes: UNIX file
    Names: »gcd.c«

Derivation

└─⟦f27320a65⟧ Bits:30001972 Commodore 900 hard disk image with partial source code
    └─⟦f4b8d8c84⟧ UNIX V7 Filesystem
        └─ ⟦this⟧ »libmp/gcd.c« 

TextFile

#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;
}