Skip to content
Snippets Groups Projects
Unverified Commit 2e054ce9 authored by Shaopeng Wang's avatar Shaopeng Wang Committed by GitHub
Browse files

Fixed128: fix dividend zero checked_div panic. (#125)

parent 714efa56
No related branches found
No related tags found
No related merge requests found
......@@ -92,6 +92,10 @@ impl Fixed128 {
if rhs.0.signum() == 0 {
return None;
}
if self.0 == 0 {
return Some(*self);
}
let signum = self.0.signum() / rhs.0.signum();
let mut lhs: i128 = self.0;
if lhs.is_negative() {
......@@ -426,6 +430,14 @@ mod tests {
assert_eq!(a.checked_div_int(&0i32), None);
}
#[test]
fn checked_div_with_zero_dividend_should_be_zero() {
let a = Fixed128::zero();
let b = Fixed128::from_parts(1);
assert_eq!(a.checked_div(&b), Some(Fixed128::zero()));
}
#[test]
fn under_flow_should_be_none() {
let b = Fixed128::from_natural(1);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment