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

⟦91789cfba⟧ TextFile

    Length: 682 (0x2aa)
    Types: TextFile
    Notes: UNIX file
    Names: »norm.c«

Derivation

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

TextFile

#include "mprec.h"


/*
 *	Norm normalizes the mint pointed to by "a".  This simply entails
 *	propogating any carry and truncating any leading 00 or NEFL bytes.
 *	Note that norm assumes that there is enough room for the result.
 */

void
norm(a)
mint *a;
{
	register unsigned char *ap, *limit;
	register int carry;

	ap = (unsigned char *)a->val;
	limit = ap + a->len;
	carry = 0;
	do {
		carry += *ap;
		*ap++ = carry % BASE;
		carry >>= L2BASE;
	} while (ap < limit);
	--ap;
	limit = a->val;
	if (*ap == NEFL) {
		while (*ap == NEFL && ap >= limit)
			--ap;
		++ap;
	} else {
		while (*ap == 0 && ap > limit)
			--ap;
		if (*ap == NEFL)
			++ap;
	}
	a->len = 1 + ap - a->val;
}