Skip to content

Commit

Permalink
copr: fix neg sign when decimal divide to zero (#11302) (#11335)
Browse files Browse the repository at this point in the history
ref #11302, close pingcap/tidb#29586

Signed-off-by: ti-srebot <ti-srebot@pingcap.com>

Co-authored-by: Zhuomin Liu <lzmhhh123@gmail.com>
Co-authored-by: Ti Chi Robot <ti-community-prow-bot@tidb.io>
  • Loading branch information
3 people committed Apr 15, 2022
1 parent eb03ae2 commit fab70cf
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion components/tidb_query_datatype/src/codec/mysql/decimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,9 @@ fn do_div_mod_impl(
let dest = &mut res.word_buf[idx_to..idx_to + src.len()];
dest.copy_from_slice(src);
}
if res.is_zero() {
res.negative = false
}
Some(res)
}

Expand Down Expand Up @@ -3495,9 +3498,23 @@ mod tests {
0,
"-0.000000000000000000000000000000000000000000004078816115216077",
"770994069125765500000000000000000000000000000",
Some("-0.000000000000000000000000000000000000000000000000000000000000000"),
Some("0.000000000000000000000000000000000000000000000000000000000000000"),
Some("-0.000000000000000000000000000000000000000000004078816115216077"),
),
(
DEFAULT_DIV_FRAC_INCR,
"-125",
"489466941506",
Some("0.000000000"),
Some("-125"),
),
(
DEFAULT_DIV_FRAC_INCR,
"-56",
"489466941506",
Some("0.000000000"),
Some("-56"),
),
];

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

0 comments on commit fab70cf

Please sign in to comment.