File:  [MW Coherent from dump] / coherent / d / usr / lib / libmp / norm.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"


/*
 *	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;
}

unix.superglobalmegacorp.com

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