-
Notifications
You must be signed in to change notification settings - Fork 63
Closed
Labels
Description
It's possible to panic with a zero division by using checked_div.
#![allow(dead_code)]
#![warn(clippy::pedantic)]
use num_rational::Ratio;
use num_traits::ops::checked::CheckedDiv;
fn main() {
#[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)]
let x = Ratio::from(0);
dbg!(x.checked_div(&x));
}The reason seems to be that the gcds are divided unsafely:
Line 779 in 957e232
| .checked_mul(&(rhs.numer.clone() / gcd_ac.clone()))?; |
Probably, one should use otry!(checked_div(...) or something similar.