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(); }
/** * Counts the number of significative digits of $val. * Assumes a consistent internal state (without zeros at the end or the start). * * @param Decimal $val * @param Decimal $abs $val->abs() * @return integer */ private static function countSignificativeDigits(Decimal $val, Decimal $abs) { return strlen($val->value) - ($abs->comp(DecimalConstants::One()) === -1 ? 2 : max($val->scale, 1)) - ($val->isNegative() ? 1 : 0); }
/** * @expectedException \DomainException * @expectedExceptionMessage The tangent of this 'angle' is undefined. */ public function testTanPiTwoDiv() { $PiDividedByTwo = DecimalConstants::PI()->div(Decimal::fromInteger(2)); $PiDividedByTwo->tan(); }
/** * @expectedException \InvalidArgumentException * @expectedExceptionMessage $scale must be positive. */ public function testNegativeParamsOnE() { DecimalConstants::e(-3); }
function testDecimalPropValid() { $this->assertFormValid("foo=1", new Check\Decimal(), DecimalConstants::one()); }
public function testNegativeWithPositiveExponent() { $nFive = Decimal::fromInteger(-5); $this->assertTrue($nFive->pow(DecimalConstants::One())->equals($nFive)); $this->assertTrue($nFive->pow(Decimal::fromInteger(2))->equals(Decimal::fromInteger(25))); $this->assertTrue($nFive->pow(Decimal::fromInteger(3))->equals(Decimal::fromInteger(-125))); }
/** * @expectedException \DomainException * @expectedExceptionMessage The cotangent of this 'angle' is undefined. */ public function testCotanPiDiv() { $PI = DecimalConstants::PI(); $PI->cotan(); }
/** * @expectedException \DomainException * @expectedExceptionMessage Infinite elevated to zero is undefined. */ public function testNegativeInfiniteZeroPower() { InfiniteDecimal::getNegativeInfinite()->pow(DecimalConstants::Zero()); }
/** * 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(); } }