Exemple #1
0
 /**
  * Returns the quotient and remainder of the division of this number by the given one.
  *
  * @param BigNumber|number|string $that The divisor. Must be convertible to a BigInteger.
  *
  * @return BigInteger[] An array containing the quotient and the remainder.
  *
  * @throws DivisionByZeroException If the divisor is zero.
  */
 public function quotientAndRemainder($that)
 {
     $that = BigInteger::of($that);
     if ($that->value === '0') {
         throw DivisionByZeroException::divisionByZero();
     }
     list($quotient, $remainder) = Calculator::get()->divQR($this->value, $that->value);
     return [new BigInteger($quotient), new BigInteger($remainder)];
 }
Exemple #2
0
 /**
  * Returns the quotient and remainder of the division of this number by the given one.
  *
  * The quotient has a scale of `0`, and the remainder has a scale of `max($this->scale, $that->scale)`.
  *
  * @param BigNumber|number|string $that The divisor. Must be convertible to a BigDecimal.
  *
  * @return BigDecimal[] An array containing the quotient and the remainder.
  *
  * @throws ArithmeticException If the divisor is not a valid decimal number, or is zero.
  */
 public function quotientAndRemainder($that)
 {
     $that = BigDecimal::of($that);
     if ($that->isZero()) {
         throw DivisionByZeroException::divisionByZero();
     }
     $p = $this->valueWithMinScale($that->scale);
     $q = $that->valueWithMinScale($this->scale);
     list($quotient, $remainder) = Calculator::get()->divQR($p, $q);
     $scale = $this->scale > $that->scale ? $this->scale : $that->scale;
     $quotient = new BigDecimal($quotient, 0);
     $remainder = new BigDecimal($remainder, $scale);
     return [$quotient, $remainder];
 }