1
0
mirror of https://github.com/danog/math.git synced 2024-11-27 04:14:40 +01:00

Change Money::dividedBy() parameter order

This commit is contained in:
Benjamin Morel 2015-06-04 21:45:13 +02:00
parent 4f3095cca1
commit c642d0d0c9
2 changed files with 11 additions and 13 deletions

View File

@ -246,15 +246,12 @@ class BigDecimal implements \Serializable
* Returns the result of the division of this number and the given one.
*
* @param BigDecimal|number|string $that The number to divide.
* @param integer|null $scale The scale, or null to use the scale of this number.
* @param integer $roundingMode The rounding mode.
* @param int $roundingMode The rounding mode.
* @param int|null $scale The desired scale, or null to use the scale of this number.
*
* @return BigDecimal
*
* @throws ArithmeticException If the divisor is zero or rounding is necessary.
* @throws \InvalidArgumentException If the divisor, the scale or the rounding mode is invalid.
*/
public function dividedBy($that, $scale = null, $roundingMode = RoundingMode::UNNECESSARY)
public function dividedBy($that, $roundingMode = RoundingMode::UNNECESSARY, $scale = null)
{
$that = BigDecimal::of($that);
@ -357,7 +354,7 @@ class BigDecimal implements \Serializable
return $this;
}
return $this->dividedBy(1, $scale, $roundingMode);
return $this->dividedBy(1, $roundingMode, $scale);
}
/**
@ -626,7 +623,7 @@ class BigDecimal implements \Serializable
return BigInteger::of($this->value);
}
return BigInteger::of($this->dividedBy(1, 0, $roundingMode)->value);
return BigInteger::of($this->dividedBy(1, $roundingMode, 0)->value);
}
/**

View File

@ -544,7 +544,7 @@ class BigDecimalTest extends AbstractTestCase
*/
public function testDividedBy($a, $b, $scale, $roundingMode, $unscaledValue, $expectedScale)
{
$decimal = BigDecimal::of($a)->dividedBy($b, $scale, $roundingMode);
$decimal = BigDecimal::of($a)->dividedBy($b, $roundingMode, $scale);
$this->assertBigDecimalEquals($unscaledValue, $expectedScale, $decimal);
}
@ -601,7 +601,7 @@ class BigDecimalTest extends AbstractTestCase
*/
public function testDividedByWithRoundingNecessaryThrowsException($a, $b, $scale)
{
BigDecimal::of($a)->dividedBy($b, $scale);
BigDecimal::of($a)->dividedBy($b, RoundingMode::UNNECESSARY, $scale);
}
/**
@ -621,7 +621,7 @@ class BigDecimalTest extends AbstractTestCase
*/
public function testDividedByWithNegativeScaleThrowsException()
{
BigDecimal::of(1)->dividedBy(2, -1);
BigDecimal::of(1)->dividedBy(2, RoundingMode::UNNECESSARY, -1);
}
/**
@ -629,7 +629,7 @@ class BigDecimalTest extends AbstractTestCase
*/
public function testDividedByWithInvalidRoundingModeThrowsException()
{
BigDecimal::of(1)->dividedBy(2, 1, -1);
BigDecimal::of(1)->dividedBy(2, -1);
}
/**
@ -664,7 +664,7 @@ class BigDecimalTest extends AbstractTestCase
$this->setExpectedException(ArithmeticException::class);
}
$actual = $number->dividedBy($divisor, $scale, $roundingMode);
$actual = $number->dividedBy($divisor, $roundingMode, $scale);
if ($expected !== null) {
$this->assertBigDecimalEquals($expected, $scale, $actual);
@ -1139,6 +1139,7 @@ class BigDecimalTest extends AbstractTestCase
[RoundingMode::UNNECESSARY, '-3.501', null, null, null],
];
}
/**
* @dataProvider providerDivideAndRemainder
*