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

coprocessor: fix do_div_mod bug #2456

Merged
merged 3 commits into from Nov 8, 2017
Merged
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
23 changes: 22 additions & 1 deletion src/coprocessor/codec/mysql/decimal.rs
Expand Up @@ -591,7 +591,7 @@ fn do_div_mod(
let mut buf = vec![0; l_len];
(&mut buf[0..i]).copy_from_slice(&lhs.word_buf[l_idx..l_idx + i]);
let mut l_idx = 0;
let (r_start, mut r_stop) = (r_idx, word_cnt!(r_idx + r_prec as usize, usize) - 1);
let (r_start, mut r_stop) = (r_idx, r_idx + word_cnt!(r_prec as usize, usize) - 1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any tests to cover it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BusyJay I'm adding test cases, please wait a minute.

while rhs.word_buf[r_stop] == 0 && r_stop >= r_start {
r_stop -= 1;
}
Expand Down Expand Up @@ -2969,6 +2969,27 @@ mod test {
(0, "1", "2.0", Some("0.500000000"), Some("1.0")),
(0, "1.0", "2", Some("0.500000000"), Some("1.0")),
(0, "2.23", "3", Some("0.743333333"), Some("2.23")),
(
DEFAULT_DIV_FRAC_INCR,
"51",
"0.003430",
Some("14868.804664723032069970"),
Some("0.002760"),
),
(
5,
"51",
"0.003430",
Some("14868.804664723032069970"),
Some("0.002760"),
),
(
0,
"51",
"0.003430",
Some("14868.804664723"),
Some("0.002760"),
),
];

for (frac_incr, lhs_str, rhs_str, div_exp, rem_exp) in cases {
Expand Down