public function __invoke($value) : ValidationResult { Assertion::numeric($value); $decimalValue = Decimal::fromString((string) $value); $floorModulo = $this->floorModulo($decimalValue->sub($this->base), $this->step); if ($floorModulo->comp(DecimalConstants::zero()) !== 0) { return new ValidationResult(new ValidationError('error.step-number', ['lowValue' => $this->trimZeroDecimal((string) $decimalValue->sub($floorModulo)), 'highValue' => $this->trimZeroDecimal((string) $decimalValue->add($this->step)->sub($floorModulo))])); } return new ValidationResult(); }
/** * Internal method used to compute arctan and arccotan * * @param Decimal $x * @param Decimal $firstTerm * @param $scale * @return 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); }
/** * Returns exp($this), said in other words: e^$this . * * @param integer $scale * @return Decimal */ public function exp($scale = null) { if ($this == self::$pInf) { return $this; } else { return DecimalConstants::zero(); } }