private static function powerSerie (Decimal $x, Decimal $firstTerm, int $scale): Decimal
    {
        $approx = $firstTerm;
        $change = DecimalConstants::One();

        $xPowerN = DecimalConstants::One();     // Calculates x^n
        $factorN = DecimalConstants::One();      // Calculates a_n

        $numerator = DecimalConstants::one();
        $denominator = DecimalConstants::one();

        for ($i = 1; !$change->floor($scale + 2)->isZero(); $i++) {
            $xPowerN = $xPowerN->mul($x);

            if ($i % 2 === 0) {
                $factorN = DecimalConstants::zero();
            } elseif ($i === 1) {
                $factorN = DecimalConstants::one();
            } else {
                $incrementNum = Decimal::fromInteger($i - 2);
                $numerator = $numerator->mul($incrementNum, $scale +2);

                $incrementDen = Decimal::fromInteger($i - 1);
                $increment = Decimal::fromInteger($i);
                $denominator = $denominator
                    ->div($incrementNum, $scale +2)
                    ->mul($incrementDen, $scale +2)
                    ->mul($increment, $scale +2);

                $factorN = $numerator->div($denominator, $scale + 2);
            }

            if (!$factorN->isZero()) {
                $change = $factorN->mul($xPowerN, $scale + 2);
                $approx = $approx->add($change, $scale + 2);
            }
        }

        return $approx->round($scale);
    }
private static function powerSerie (Decimal $x, Decimal $firstTerm, int $scale): Decimal
    {
        $approx = $firstTerm;
        $change = DecimalConstants::One();

        $xPowerN = DecimalConstants::One();     // Calculates x^n
        $factorN = DecimalConstants::One();      // Calculates a_n

        $numerator = DecimalConstants::one();
        $denominator = DecimalConstants::one();

        for ($i = 1; !$change->floor($scale + 2)->isZero(); $i++) {
            $xPowerN = $xPowerN->mul($x);

            if ($i % 2 === 0) {
                $factorN = DecimalConstants::zero();
            } elseif ($i === 1) {
                $factorN = DecimalConstants::one();
            } else {
                $incrementNum = Decimal::fromInteger($i - 2);
                $numerator = $numerator->mul($incrementNum, $scale +2);

                $incrementDen = Decimal::fromInteger($i - 1);
                $increment = Decimal::fromInteger($i);
                $denominator = $denominator
                    ->div($incrementNum, $scale +2)
                    ->mul($incrementDen, $scale +2)
                    ->mul($increment, $scale +2);

                $factorN = $numerator->div($denominator, $scale + 2);
            }

            if (!$factorN->isZero()) {
                $change = $factorN->mul($xPowerN, $scale + 2);
                $approx = $approx->add($change, $scale + 2);
            }
        }

        return $approx->round($scale);
    }
private static function powerSerie ( Decimal $ x , Decimal $ firstTerm , int $ scale ) : Decimal { $ approx = $ firstTerm ; $ change = DecimalConstants :: One ( ) ; $ xPowerN = DecimalConstants :: One ( ) ; // Calculates x^n $ factorN = DecimalConstants :: One ( ) ; // Calculates a_n $ numerator = DecimalConstants :: one ( ) ; $ denominator = DecimalConstants :: one ( ) ; for ( $ i = 1 ; ! $ change -> floor ( $ scale + 2 ) -> isZero ( ) ; $ i ++ ) { $ xPowerN = $ xPowerN -> mul ( $ x ) ; if ( $ i % 2 === 0 ) { $ factorN = DecimalConstants :: zero ( ) ; } elseif ( $ i === 1 ) { $ factorN = DecimalConstants :: one ( ) ; } else { $ incrementNum = Decimal :: fromInteger ( $ i - 2 ) ; $ numerator = $ numerator -> mul ( $ incrementNum , $ scale + 2 ) ; $ incrementDen = Decimal :: fromInteger ( $ i - 1 ) ; $ increment = Decimal :: fromInteger ( $ i ) ; $ denominator = $ denominator -> div ( $ incrementNum , $ scale + 2 ) -> mul ( $ incrementDen , $ scale + 2 ) -> mul ( $ increment , $ scale + 2 ) ; $ factorN = $ numerator -> div ( $ denominator , $ scale + 2 ) ; } if ( ! $ factorN -> isZero ( ) ) { $ change = $ factorN -> mul ( $ xPowerN , $ scale + 2 ) ; $ approx = $ approx -> add ( $ change , $ scale + 2 ) ; } } return $ approx -> round ( $ scale ) ; }
Internal method used to compute arcsine and arcosine

@param Decimal $x
@param Decimal $firstTerm
@param $scale
@return Decimal
Internal method used to compute arcsine and arcosine