public static function fromReal(Real $real, RoundingMode $roundingMode = null, $force = true) { if (!$force && $real->lessThan(new Number(1))) { throw new ValueNotConvertibleException($real); } return parent::fromReal($real, $roundingMode, $force); }
/** * fromReal. * * @param Real $real * @param RoundingMode $roundingMode * * @return static */ public static function fromReal(Real $real, RoundingMode $roundingMode = null) { if (null === $roundingMode) { $roundingMode = RoundingMode::HALF_UP(); } $value = filter_var(round($real->value(), 0, $roundingMode->value()), FILTER_VALIDATE_INT); return new static($value); }
/** * Returns a Complex given polar coordinates * * @param Real $modulus * @param Real $argument * @return Complex */ public static function fromPolar(Real $modulus, Real $argument) { $realValue = $modulus->toNative() * \cos($argument->toNative()); $imValue = $modulus->toNative() * \sin($argument->toNative()); $real = new Real($realValue); $im = new Real($imValue); $complex = new static($real, $im); return $complex; }
/** * fromReal. * * @param Real $real * @param RoundingMode $roundingMode * @param bool $force * * @return static */ public static function fromReal(Real $real, RoundingMode $roundingMode = null, $force = true) { if (!$force && $real->lessThan(new Number(0))) { throw new ValueNotConvertibleException($real); } if (null === $roundingMode) { $roundingMode = RoundingMode::HALF_UP(); } $naturalValue = abs(Integer::fromReal($real, $roundingMode)->value()); return new static($naturalValue); }
/** * Returns the value of the integer number * * @return int */ public function toNative() { $value = parent::toNative(); return \intval($value); }
public function testGetArgument() { $arg = new Real(1.0010398733119); $this->assertTrue($arg->sameValueAs($this->complex->getArgument())); }
/** * Multiply the Money amount for a given number and returns a new Money object. * Use 0 < Real $multipler < 1 for division. * * @param Real $multiplier * @param mixed $rounding_mode Rounding mode of the operation. Defaults to RoundingMode::HALF_UP. * @return Money */ public function multiply(Real $multiplier, RoundingMode $rounding_mode = null) { if (null === $rounding_mode) { $rounding_mode = RoundingMode::HALF_UP(); } $amount = $this->getAmount()->toNative() * $multiplier->toNative(); $roundedAmount = new Integer(round($amount, 0, $rounding_mode->toNative())); $result = new self($roundedAmount, $this->getCurrency()); return $result; }
public function testNegativeToNaturalHalfUp() { $real = new Real(-0.5); $natural = $real->toNatural(RoundingMode::HALF_UP()); $this->assertInstanceOf(Natural::class, $natural); $this->assertSame(1, $natural->value()); }
public function testToString() { $real = new Real(0.7); $this->assertEquals('.7', $real->__toString()); }