Author: Andreu Correa Casablanca (castarco@litipk.com)
コード例 #1
0
 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();
 }
コード例 #2
0
 /**
  * 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);
 }
コード例 #3
0
 /**
  * @expectedException \DomainException
  * @expectedExceptionMessage The tangent of this 'angle' is undefined.
  */
 public function testTanPiTwoDiv()
 {
     $PiDividedByTwo = DecimalConstants::PI()->div(Decimal::fromInteger(2));
     $PiDividedByTwo->tan();
 }
コード例 #4
0
 /**
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessage $scale must be positive.
  */
 public function testNegativeParamsOnE()
 {
     DecimalConstants::e(-3);
 }
コード例 #5
0
ファイル: FormSchemaTest.php プロジェクト: shabbyrobe/fulfil
 function testDecimalPropValid()
 {
     $this->assertFormValid("foo=1", new Check\Decimal(), DecimalConstants::one());
 }
コード例 #6
0
 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)));
 }
コード例 #7
0
 /**
  * @expectedException \DomainException
  * @expectedExceptionMessage The cotangent of this 'angle' is undefined.
  */
 public function testCotanPiDiv()
 {
     $PI = DecimalConstants::PI();
     $PI->cotan();
 }
コード例 #8
0
 /**
  * @expectedException \DomainException
  * @expectedExceptionMessage Infinite elevated to zero is undefined.
  */
 public function testNegativeInfiniteZeroPower()
 {
     InfiniteDecimal::getNegativeInfinite()->pow(DecimalConstants::Zero());
 }
コード例 #9
0
 /**
  * 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();
     }
 }