Litipk\BigNumbers\Decimal::innerLog10 PHP Method

innerLog10() private static method

Calculates the logarithm (in base 10) of $value
private static innerLog10 ( string $value, integer $in_scale, integer $out_scale ) : string
$value string The number we want to calculate its logarithm (only positive numbers)
$in_scale integer Expected scale used by $value (only positive numbers)
$out_scale integer Scale used by the return value (only positive numbers)
return string
    private static function innerLog10($value, $in_scale, $out_scale)
    {
        $value_len = strlen($value);
        $cmp = bccomp($value, '1', $in_scale);
        switch ($cmp) {
            case 1:
                $value_log10_approx = $value_len - ($in_scale > 0 ? $in_scale + 2 : 1);
                return bcadd($value_log10_approx, log10(bcdiv($value, bcpow('10', $value_log10_approx), min($value_len, $out_scale))), $out_scale);
            case -1:
                preg_match('/^0*\\.(0*)[1-9][0-9]*$/', $value, $captures);
                $value_log10_approx = -strlen($captures[1]) - 1;
                return bcadd($value_log10_approx, log10(bcmul($value, bcpow('10', -$value_log10_approx), $in_scale + $value_log10_approx)), $out_scale);
            default:
                // case 0:
                return '0';
        }
    }