Litipk\BigNumbers\Decimal::innerPowWithLittleExponent PHP Method

innerPowWithLittleExponent() private static method

Returns $base^$exponent
private static innerPowWithLittleExponent ( string $base, string $exponent, integer $exp_scale, integer $out_scale ) : string
$base string
$exponent string 0 < $exponent < 1
$exp_scale integer Number of $exponent's significative digits
$out_scale integer Number of significative digits that we want to compute
return string
    private static function innerPowWithLittleExponent($base, $exponent, $exp_scale, $out_scale)
    {
        $inner_scale = ceil($exp_scale * log(10) / log(2)) + 1;
        $result_a = '1';
        $result_b = '0';
        $actual_index = 0;
        $exponent_remaining = $exponent;
        while (bccomp($result_a, $result_b, $out_scale) !== 0 && bccomp($exponent_remaining, '0', $inner_scale) !== 0) {
            $result_b = $result_a;
            $index_info = self::computeSquareIndex($exponent_remaining, $actual_index, $exp_scale, $inner_scale);
            $exponent_remaining = $index_info[1];
            $result_a = bcmul($result_a, self::compute2NRoot($base, $index_info[0], 2 * ($out_scale + 1)), 2 * ($out_scale + 1));
        }
        return self::innerRound($result_a, $out_scale);
    }