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

1.1     ! root        1: #include "mprec.h"
        !             2: 
        !             3: 
        !             4: /*
        !             5:  *     Rpow sets the mint pointed to by "c" to the mint pointed to by "a"
        !             6:  *     raised to the mint pointed to by "b" power.  If "b" is negative then
        !             7:  *     mperr is called with the appropriate error message.
        !             8:  *     Note that no assumption is made as to the distinctness of "a", "b" and
        !             9:  *     "c".
        !            10:  */
        !            11: 
        !            12: void
        !            13: rpow(a, b, c)
        !            14: register mint *a, *b, *c;
        !            15: {
        !            16:        mint    al, bl;
        !            17:        int rem;
        !            18: 
        !            19:        if (!ispos(b))
        !            20:                mperr("negative power");
        !            21: 
        !            22:        /* make local copies of a and b */
        !            23:        minit(&al);
        !            24:        mcopy(a, &al);
        !            25:        minit(&bl);
        !            26:        mcopy(b, &bl);
        !            27: 
        !            28:        /* form actual power */
        !            29:        sdiv(&bl, 2, &bl, &rem);
        !            30:        if (rem != 0)
        !            31:                mcopy(&al, c);
        !            32:        else
        !            33:                mcopy(mone, c);
        !            34:        while (!zerop(&bl)) {
        !            35:                mult(&al, &al, &al);
        !            36:                sdiv(&bl, 2, &bl, &rem);
        !            37:                if (rem != 0)
        !            38:                        mult(c, &al, c);
        !            39:        }
        !            40: 
        !            41:        /* clean up garbage */
        !            42:        mpfree(al.val);
        !            43:        mpfree(bl.val);
        !            44: }

unix.superglobalmegacorp.com

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