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

⟦711a16ef9⟧ TextFile

    Length: 799 (0x31f)
    Types: TextFile
    Notes: UNIX file
    Names: »rpow.c«

Derivation

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

TextFile

#include "mprec.h"


/*
 *	Rpow sets the mint pointed to by "c" to the mint pointed to by "a"
 *	raised to the mint pointed to by "b" power.  If "b" is negative then
 *	mperr is called with the appropriate error message.
 *	Note that no assumption is made as to the distinctness of "a", "b" and
 *	"c".
 */

void
rpow(a, b, c)
register mint *a, *b, *c;
{
	mint	al, bl;
	int rem;

	if (!ispos(b))
		mperr("negative power");

	/* make local copies of a and b */
	minit(&al);
	mcopy(a, &al);
	minit(&bl);
	mcopy(b, &bl);

	/* form actual power */
	sdiv(&bl, 2, &bl, &rem);
	if (rem != 0)
		mcopy(&al, c);
	else
		mcopy(mone, c);
	while (!zerop(&bl)) {
		mult(&al, &al, &al);
		sdiv(&bl, 2, &bl, &rem);
		if (rem != 0)
			mult(c, &al, c);
	}

	/* clean up garbage */
	mpfree(al.val);
	mpfree(bl.val);
}