diff --git a/src/BigInteger.php b/src/BigInteger.php index 8d45767..176fe0e 100644 --- a/src/BigInteger.php +++ b/src/BigInteger.php @@ -331,6 +331,22 @@ public function divideAndRemainder($that) return [$quotient, $remainder]; } + /** + * Returns the remainder of the division of this number and the given one. + * + * @param BigInteger|int|string $that + * + * @return BigInteger + */ + public function remainder($that) + { + $that = BigInteger::of($that); + + list (, $remainder) = Calculator::get()->div($this->value, $that->value); + + return new BigInteger($remainder); + } + /** * Returns this number exponentiated. * diff --git a/tests/BigIntegerTest.php b/tests/BigIntegerTest.php index 334a7fb..e812c16 100644 --- a/tests/BigIntegerTest.php +++ b/tests/BigIntegerTest.php @@ -1104,6 +1104,21 @@ public function testDivideAndRemainderByZeroThrowsException() BigInteger::of(1)->divideAndRemainder(0); } + /** + * @dataProvider providerDivideAndRemainder + * + * @param string $dividend The dividend. + * @param string $divisor The divisor. + * @param string $quotient The expected quotient (ignore for this test). + * @param string $remainder The expected remainder. + */ + public function testRemainder($dividend, $divisor, $quotient, $remainder) + { + list (, $r) = BigInteger::of($dividend)->divideAndRemainder($divisor); + + $this->assertSame($remainder, (string) $r); + } + /** * @dataProvider providerPower *