Skip to content

Commit 0bcd11a

Browse files
committed
Fix division by zero
1 parent 5cc30e0 commit 0bcd11a

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

src/f62.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -298,10 +298,7 @@ impl Div for Float62 {
298298
return operate_float(self, rhs, f64::div);
299299
};
300300

301-
if y == 0 {
302-
// TODO Fix this
303-
Self::from_float(f64::NAN)
304-
} else if x % y == 0 {
301+
if y != 0 && x % y == 0 {
305302
Self::from_integer(x / y)
306303
} else {
307304
Self::from_float(x as f64 / y as f64)
@@ -689,7 +686,15 @@ mod tests {
689686

690687
#[test]
691688
fn div_by_zero() {
692-
assert!((Float62::from_integer(1) / Float62::from_integer(0)).is_nan());
689+
assert_eq!(
690+
Float62::from_integer(1) / Float62::from_integer(0),
691+
Float62::from_float(f64::INFINITY)
692+
);
693+
assert_eq!(
694+
Float62::from_integer(-1) / Float62::from_integer(0),
695+
Float62::from_float(f64::NEG_INFINITY)
696+
);
697+
assert!((Float62::from_integer(0) / Float62::from_integer(0)).is_nan());
693698
assert_eq!(
694699
Float62::from_float(6.0) / Float62::from_integer(0),
695700
Float62::from_float(f64::INFINITY)

0 commit comments

Comments
 (0)