Same as bcpowmod when bcpowmod is missing

@access private
@param int $base
@param int $exponent
@param int $modulus
@return int
9230
function _powmod($base, $exponent, $modulus)
    {
        $square = $this->mod($base, $modulus);
        $result = 1;
        while($this->cmp($exponent, 0) > 0) {
            if ($this->mod($exponent, 2)) {
                $result = $this->mod($this->mul($result, $square), $modulus);
            }
            $square = $this->mod($this->mul($square, $square), $modulus);
            $exponent = $this->div($exponent, 2);
        }
        return $result;
    }
251610
public static function mod($n, $d)
    {
        if (function_exists('gmp_mod')) {
            return gmp_mod($n, $d);
        }

        return bcmod($n, $d);
    }
621227
def modular_exponential(base, exponent, mod):
    """"""
    if exponent < 0:
        raise ValueError("Exponent must be positive.")
    base %= mod
    result = 1

    while exponent > 0:
        # If the last bit is 1, add 2^k.
        if exponent & 1:
            result = (result * base) % mod
        exponent = exponent >> 1
        # Utilize modular multiplication properties to combine the computed mod C values.
        base = (base * base) % mod

    return result
332982
public static function exponentiate(self $key, BigInteger $c): BigInteger
    {
        if ($c->compare(BigInteger::createFromDecimal(0)) < 0 || $c->compare($key->getModulus()) > 0) {
            throw new \RuntimeException();
        }
        if ($key->isPublic() || empty($key->getPrimes()) || empty($key->getExponents()) || null === $key->getCoefficient()) {
            return $c->modPow($key->getExponent(), $key->getModulus());
        }

        $p = $key->getPrimes()[0];
        $q = $key->getPrimes()[1];
        $dP = $key->getExponents()[0];
        $dQ = $key->getExponents()[1];
        $qInv = $key->getCoefficient();

        $m1 = $c->modPow($dP, $p);
        $m2 = $c->modPow($dQ, $q);
        $h = $qInv->multiply($m1->subtract($m2)->add($p))->mod($p);
        $m = $m2->add($h->multiply($q));

        return $m;
    }
534302
private static function modulo($x, $y)
    {
        return ($x < $y ? $x : (is_int($y) ? $x % $y : fmod($x, $y))) + ($x < 0 ? $y : 0);
    }
917514
def mod(ctx, number, divisor):
    
    number = conversions.to_decimal(number, ctx)
    divisor = conversions.to_decimal(divisor, ctx)
    return number - divisor * _int(ctx, number / divisor)
832198
public boolean validateModcaString8(String modcaString8, DiagnosticChain diagnostics, Map<Object, Object> context) {
		boolean result = validateModcaString8_MinLength(modcaString8, diagnostics, context);
		if (result || diagnostics != null) result &= validateModcaString8_MaxLength(modcaString8, diagnostics, context);
		return result;
	}
1035321
public static long pow(final long b, final long e) {
		long base = b;
		long exp = e;
		long result = 1;

		while (exp != 0) {
			if ((exp & 1) != 0) {
				result *= base;
			}
			exp >>>= 1;
			base *= base;
		}

		return result;
	}
1288528
public static int setPublic(int modifier, boolean b) {
        if (b) {
            return (modifier | PUBLIC) & (~PROTECTED & ~PRIVATE);
        }
        else {
            return modifier & ~PUBLIC;
        }
    }
957766
public function inv($number, $modulus)
    {
        if ($this->coprime($number, $modulus) === false) {
            return '0';
        }

        $a = '1';
        $b = '0';
        $z = '0';
        $c = '0';

        list($modulus, $number) = array($this->bcNormalize($modulus), $this->bcNormalize($number));
        list($mod, $num)        = array($modulus, $number);

        try {

            do {
                list($z, $c)     = $this->modDiv($num, $mod);
                list($mod, $num) = array($z, $mod);

                $z = $this->subMul($a, $b, $c);

                list($a, $b) = array($b, $z);
            } while (bccomp($mod, '0') > 0);

            return $this->addMod($a, $modulus);

        } catch (\Exception $e) {
            throw $e;
        }
    }
1141308
public function checkModRewrite()
    {
        $iModStat = null;
        $aHostInfo = $this->_getShopHostInfo();
        $iModStat = $this->_checkModRewrite($aHostInfo);

        $aSSLHostInfo = $this->_getShopSSLHostInfo();
        // Don't need to check if mod status is already failed.
        if (0 != $iModStat && $aSSLHostInfo) {
            $iSSLModStat = $this->_checkModRewrite($aSSLHostInfo);

            // Send if failed, even if couldn't check another
            if (0 == $iSSLModStat) {
                return 0;
            } elseif (1 == $iSSLModStat || 1 == $iModStat) {
                return 1;
            }

            return min($iModStat, $iSSLModStat);
        }

        return $iModStat;
    }
1296914
function (nb, base) {
		var pow = 0;
		if (nb < 0)
			nb = -nb;
		base = base || 10;
		while (nb >= base) {
			nb = nb / base;
			++pow;
		}
		return pow;
	}
531018
public static double pow(Number baseNumber, int exponent) {
        return exponent < 1 ? 1
                : exponent > 1
                ? baseNumber.doubleValue()
                * pow(baseNumber, exponent - 1)
                : baseNumber.doubleValue();
    }
1243809
public function invertm($num, $mod)
    {
        $num = $this->input($num);
        $mod = $this->input($mod);

        $x = '1';
        $y = '0';
        $num1 = $mod;

        do {
            $tmp = bcmod($num, $num1);

            $q = bcdiv($num, $num1);

            $num = $num1;

            $num1 = $tmp;

            $tmp = bcsub($x, bcmul($y, $q));

            $x = $y;

            $y = $tmp;

        } while (bccomp($num1, '0'));

        if (bccomp($x, '0') < 0) {
            $x = bcadd($x, $mod);
        }

        if (substr($num, 0, 1) === '-') {
            $x = bcsub($mod, $x);
        }

        return $x;
    }
1359729
public function powmod($a, $b, $c)
    {
        return bcpowmod($this->bcNormalize($a), $this->bcNormalize($b), $this->bcNormalize($c));
    }
883631
static long power(long base, short exponent) {
        if (exponent < 0) {
            throw new IllegalArgumentException("Exponent can not be negative");
        }
        if (base < 0) {
            throw new IllegalArgumentException("Base can not be negative");
        }
        long result = 1;
        while (exponent > 0) {
            if ((exponent & 1) == 1) {
                result *= base;
            }
            base *= base;
            exponent >>= 1;
        }
        return result;
    }
1005528
public static long powExact(long b, int k) {
        checkNonNegative("exponent", k);
        if (b >= -2 & b <= 2) {
            switch ((int) b) {
                case 0:
                    return (k == 0) ? 1 : 0;
                case 1:
                    return 1;
                case (-1):
                    return ((k & 1) == 0) ? 1 : -1;
                case 2:
                    checkNoOverflow(k < Long.SIZE - 1);
                    return 1L << k;
                case (-2):
                    checkNoOverflow(k < Long.SIZE);
                    return ((k & 1) == 0) ? (1L << k) : (-1L << k);
                default:
                    throw new AssertionError();
            }
        }
        long accum = 1;
        while (true) {
            switch (k) {
                case 0:
                    return accum;
                case 1:
                    return multiplyExact(accum, b);
                default:
                    if ((k & 1) != 0) {
                        accum = multiplyExact(accum, b);
                    }
                    k >>= 1;
                    if (k > 0) {
                        checkNoOverflow(-FLOOR_SQRT_MAX_LONG <= b && b <= FLOOR_SQRT_MAX_LONG);
                        b *= b;
                    }
            }
        }
    }