Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes issue with remainder overflow #393

Merged
merged 1 commit into from
Jun 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ops/div.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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())
}
}