Annotation of coherent/d/usr/lib/libmp/smult.c, revision 1.1

1.1     ! root        1: #include "mprec.h"
        !             2: #include <assert.h>
        !             3: 
        !             4: 
        !             5: /*
        !             6:  *     Smult sets the mint pointed to by "c" to the product of that pointed
        !             7:  *     to by "a" and the char "n".  Note that "n" is assumed to be between
        !             8:  *     0 and NEFL.  Also note that "a" == "c" is permissable.
        !             9:  */
        !            10: 
        !            11: void
        !            12: smult(a, n, c)
        !            13: mint *a, *c;
        !            14: char n;
        !            15: {
        !            16:        register char *rp, *ap;
        !            17:        register int carry;
        !            18:        char *limit;
        !            19:        char *res;
        !            20: 
        !            21:        assert(0 <= n && n <= NEFL);
        !            22: 
        !            23:        /* handle zero specially */
        !            24:        if (n == 0) {
        !            25:                mcopy(mzero, c);
        !            26:                return;
        !            27:        }
        !            28: 
        !            29:        /* allocate space for result */
        !            30:        rp = (char *)mpalc(a->len + 1);
        !            31:        res = rp;
        !            32: 
        !            33:        /* perform multiplication assuming a is positive */
        !            34:        ap = a->val;
        !            35:        limit = ap + a->len;
        !            36:        carry = 0;
        !            37:        while (ap < limit) {
        !            38:                carry += *ap++ * n;
        !            39:                *rp++ = carry % BASE;
        !            40:                carry >>= L2BASE;
        !            41:        }
        !            42:        --ap;
        !            43: 
        !            44:        /* if a was negative, correct carry */
        !            45:        if (!ispos(a))
        !            46:                carry += BASE - n;
        !            47: 
        !            48:        /* set carry in place and replace old c value */
        !            49:        *rp = carry;
        !            50:        assert(0 <= carry && carry <= NEFL);
        !            51:        assert((carry==NEFL && *ap==NEFL) || (carry!=NEFL && *ap!=NEFL));
        !            52:        mpfree(c->val);
        !            53:        c->val = res;
        !            54:        c->len = a->len + 1;
        !            55:        norm(c);
        !            56: }

unix.superglobalmegacorp.com

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