Litipk\BigNumbers\Decimal::simplePowerSerie PHP Méthode

simplePowerSerie() private static méthode

Internal method used to compute arctan and arccotan
private static simplePowerSerie ( Decimal $x, Decimal $firstTerm, $scale ) : Decimal
$x Decimal
$firstTerm Decimal
$scale
Résultat Decimal
    private static function simplePowerSerie(Decimal $x, Decimal $firstTerm, $scale)
    {
        $approx = $firstTerm;
        $change = InfiniteDecimal::getPositiveInfinite();
        $xPowerN = DecimalConstants::One();
        // Calculates x^n
        $sign = DecimalConstants::One();
        // Calculates a_n
        for ($i = 1; !$change->floor($scale + 2)->isZero(); $i++) {
            $xPowerN = $xPowerN->mul($x);
            if ($i % 2 === 0) {
                $factorN = DecimalConstants::zero();
            } else {
                if ($i % 4 === 1) {
                    $factorN = DecimalConstants::one()->div(Decimal::fromInteger($i), $scale + 2);
                } else {
                    $factorN = DecimalConstants::negativeOne()->div(Decimal::fromInteger($i), $scale + 2);
                }
            }
            if (!$factorN->isZero()) {
                $change = $factorN->mul($xPowerN, $scale + 2);
                $approx = $approx->add($change, $scale + 2);
            }
        }
        return $approx->round($scale);
    }