mirror of
https://github.com/shopspring/decimal.git
synced 2024-11-22 12:30:49 +01:00
This commit is contained in:
parent
1df8fb3015
commit
7b4ffbcd3c
2 changed files with 4 additions and 2 deletions
|
@ -626,8 +626,8 @@ func (d Decimal) DivRound(d2 Decimal, precision int32) Decimal {
|
|||
|
||||
// Mod returns d % d2.
|
||||
func (d Decimal) Mod(d2 Decimal) Decimal {
|
||||
quo := d.DivRound(d2, -d.exp+1).Truncate(0)
|
||||
return d.Sub(d2.Mul(quo))
|
||||
_, r := d.QuoRem(d2, 0)
|
||||
return r
|
||||
}
|
||||
|
||||
// Pow returns d to the power d2
|
||||
|
|
|
@ -2147,6 +2147,8 @@ func TestDecimal_Mod(t *testing.T) {
|
|||
Inp{"-7.5", "2"}: "-1.5",
|
||||
Inp{"7.5", "-2"}: "1.5",
|
||||
Inp{"-7.5", "-2"}: "-1.5",
|
||||
Inp{"41", "21"}: "20",
|
||||
Inp{"400000000001", "200000000001"}: "200000000000",
|
||||
}
|
||||
|
||||
for inp, res := range inputs {
|
||||
|
|
Loading…
Reference in a new issue