Skip to content

Commit

Permalink
Merge pull request #393 from paupino/issue/392
Browse files Browse the repository at this point in the history
Fixes issue with remainder overflow
  • Loading branch information
paupino committed Jun 7, 2021
2 parents e346c59 + a231fbf commit c0117dd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ops/div.rs
Expand Up @@ -196,7 +196,7 @@ impl Buf16 {
if num < prod1 {
// Detected carry.
let tmp = remainder;
remainder += 1;
remainder = remainder.wrapping_add(1);
if tmp < divisor_hi {
break;
}
Expand Down
9 changes: 9 additions & 0 deletions tests/decimal_tests.rs
Expand Up @@ -3989,4 +3989,13 @@ mod issues {
// - 714606667614253123173036.85120
assert_eq!("-714606667614253123173036.85120", c.unwrap().to_string());
}

#[test]
fn issue_392_overflow_during_remainder() {
let a = Decimal::from_str("-79228157791897.854723898738431").unwrap();
let b = Decimal::from_str("184512476.73336922111").unwrap();
let c = a.checked_div(b);
assert!(c.is_some());
assert_eq!("-429391.87200000000002327170816", c.unwrap().to_string())
}
}

0 comments on commit c0117dd

Please sign in to comment.