function BigDecimal::quotientAndRemainder
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)`.
@psalm-return array{BigDecimal, BigDecimal}
Parameters
BigNumber|int|float|string $that The divisor. Must be convertible to a BigDecimal.:
Return value
BigDecimal[] An array containing the quotient and the remainder.
Throws
MathException If the divisor is not a valid decimal number, or is zero.
File
-
vendor/
brick/ math/ src/ BigDecimal.php, line 387
Class
- BigDecimal
- Immutable, arbitrary-precision signed decimal numbers.
Namespace
Brick\MathCode
public function quotientAndRemainder(BigNumber|int|float|string $that) : array {
$that = BigDecimal::of($that);
if ($that->isZero()) {
throw DivisionByZeroException::divisionByZero();
}
$p = $this->valueWithMinScale($that->scale);
$q = $that->valueWithMinScale($this->scale);
[
$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,
];
}