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

        $faculty = DecimalConstants::One();    // Calculates the faculty under the sign
        $xPowerN = DecimalConstants::One();    // Calculates x^n

        for ($i = 1; !$change->floor($scale+1)->isZero(); $i++) {
            // update x^n and n! for this walkthrough
            $xPowerN = $xPowerN->mul($x);
            $faculty = $faculty->mul(Decimal::fromInteger($i));

            /** @var Decimal $multiplier */
            $multiplier = $generalTerm($i);

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

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

        $faculty = DecimalConstants::One();    // Calculates the faculty under the sign
        $xPowerN = DecimalConstants::One();    // Calculates x^n

        for ($i = 1; !$change->floor($scale+1)->isZero(); $i++) {
            // update x^n and n! for this walkthrough
            $xPowerN = $xPowerN->mul($x);
            $faculty = $faculty->mul(Decimal::fromInteger($i));

            /** @var Decimal $multiplier */
            $multiplier = $generalTerm($i);

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

        return $approx->round($scale);
    }
private static function factorialSerie ( Decimal $ x , Decimal $ firstTerm , callable $ generalTerm , int $ scale ) : Decimal { $ approx = $ firstTerm ; $ change = DecimalConstants :: One ( ) ; $ faculty = DecimalConstants :: One ( ) ; // Calculates the faculty under the sign $ xPowerN = DecimalConstants :: One ( ) ; // Calculates x^n for ( $ i = 1 ; ! $ change -> floor ( $ scale + 1 ) -> isZero ( ) ; $ i ++ ) { // update x^n and n! for this walkthrough $ xPowerN = $ xPowerN -> mul ( $ x ) ; $ faculty = $ faculty -> mul ( Decimal :: fromInteger ( $ i ) ) ; /** @var Decimal $multiplier */ $ multiplier = $ generalTerm ( $ i ) ; if ( ! $ multiplier -> isZero ( ) ) { $ change = $ multiplier -> mul ( $ xPowerN , $ scale + 2 ) -> div ( $ faculty , $ scale + 2 ) ; $ approx = $ approx -> add ( $ change , $ scale + 2 ) ; } } return $ approx -> round ( $ scale ) ; }
Internal method used to compute sin, cos and exp

@param Decimal $x
@param Decimal $firstTerm
@param callable $generalTerm
@param $scale
@return Decimal
Internal method used to compute sin cos and exp