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

1.1     ! root        1: #include "mprec.h"
        !             2: #include <assert.h>
        !             3: 
        !             4: 
        !             5: /*
        !             6:  *     Mneg sets the mint pointed to by "b" to negative 1 times the
        !             7:  *     mint pointed to by "a".  Note that "a" == "b" is permissable.
        !             8:  */
        !             9: 
        !            10: void
        !            11: mneg(a, b)
        !            12: mint *a, *b;
        !            13: {
        !            14:        register char *ap, *rp;
        !            15:        register unsigned count;
        !            16:        mint res;
        !            17:        int mifl;
        !            18: 
        !            19:        /* allocate result space */
        !            20:        mifl = ispos(a);
        !            21:        res.len = a->len;
        !            22:        if (mifl)
        !            23:                ++res.len;
        !            24:        res.val = (char *)mpalc(res.len);
        !            25: 
        !            26:        /* negate and copy */
        !            27:        ap = a->val;
        !            28:        rp = res.val;
        !            29:        count = a->len;
        !            30:        while (count-- > 0)
        !            31:                *rp++ = NEFL - *ap++;
        !            32:        if (mifl)
        !            33:                *rp = NEFL;
        !            34:        ++*res.val;
        !            35:        assert(ap == a->val + a->len);
        !            36:        assert(rp == res.val + res.len - (mifl ? 1 : 0));
        !            37:        norm(&res);
        !            38: 
        !            39:        /* replace old value of b with res */
        !            40:        mpfree(b->val);
        !            41:        *b = res;
        !            42: }

unix.superglobalmegacorp.com

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