Annotation of 42BSD/usr.lib/libF77/pow_ii.c, revision 1.1

1.1     ! root        1: /*
        !             2:  *     "@(#)pow_ii.c   1.2"
        !             3:  *
        !             4:  *  Corrections by Robert P. Corbett, 1983 March 2
        !             5:  *  Revised to restore portability, 1983 March 4
        !             6:  */
        !             7: 
        !             8: 
        !             9: long int pow_ii(ap, bp)
        !            10: long int *ap, *bp;
        !            11: {
        !            12:        long int pow, x, n;
        !            13:        int zero = 0;
        !            14: 
        !            15:        pow = 1;
        !            16:        x = *ap;
        !            17:        n = *bp;
        !            18: 
        !            19:        if (n == 0)
        !            20:                return ( 1L );
        !            21: 
        !            22:        if (x == 0)
        !            23:                return ( 0L );
        !            24: 
        !            25:        if (x == 1)
        !            26:                return ( 1L );
        !            27: 
        !            28:        if (x == -1)
        !            29:        {
        !            30:                if (n < 0)
        !            31:                {
        !            32:                        if (n < -2)
        !            33:                                n += 2;
        !            34:                        n = -n;
        !            35:                }
        !            36:                if (n % 2 == 0)
        !            37:                        return ( 1L );
        !            38:                else
        !            39:                        return ( -1L );
        !            40:        }
        !            41: 
        !            42:        if (n > 0)
        !            43:                for( ; ; )
        !            44:                {
        !            45:                        if(n & 01)
        !            46:                                pow *= x;
        !            47:                        if(n >>= 1)
        !            48:                                x *= x;
        !            49:                        else
        !            50:                                break;
        !            51:                }
        !            52:        else
        !            53:                pow = 0;
        !            54: 
        !            55:        return(pow);
        !            56: }

unix.superglobalmegacorp.com

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