sercantutar / infint

Arbitrary-Precision Integer Arithmetic
http://sercantutar.github.io/infint/
198 stars 48 forks source link

Simple pow function intPow #23

Closed Kischy closed 3 years ago

Kischy commented 5 years ago

How about a simple intPow function. Code copied from here. This is releated to issue #17

int ipow(int base, int exp)
{
    int result = 1;
    for (;;)
    {
        if (exp & 1)
            result *= base;
        exp >>= 1;
        if (!exp)
            break;
        base *= base;
    }

    return result;
}