Fix overflow edge case in QuoRem method (#322)

This commit is contained in:
Frank 2024-01-16 03:52:54 +08:00 committed by GitHub
parent 142a0cf2f2
commit b844c58a71
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -561,7 +561,7 @@ func (d Decimal) QuoRem(d2 Decimal, precision int32) (Decimal, Decimal) {
panic("decimal division by 0")
}
scale := -precision
e := int64(d.exp - d2.exp - scale)
e := int64(d.exp) - int64(d2.exp) - int64(scale)
if e > math.MaxInt32 || e < math.MinInt32 {
panic("overflow in decimal QuoRem")
}