Skip to content

Commit cdc653d

Browse files
committed
Improve zero denom check
1 parent df4503c commit cdc653d

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

packages/std/src/math/fraction.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use crate::Uint256;
2-
31
/// A fraction `p`/`q` with integers `p` and `q`.
42
///
53
/// `p` is called the numerator and `q` is called the denominator.
@@ -15,7 +13,7 @@ pub trait Fraction<T>: Sized {
1513
fn inv(&self) -> Option<Self>;
1614
}
1715

18-
impl<T: Copy + Into<Uint256>> Fraction<T> for (T, T) {
16+
impl<T: Copy + From<u8> + PartialEq> Fraction<T> for (T, T) {
1917
fn numerator(&self) -> T {
2018
self.0
2119
}
@@ -25,7 +23,7 @@ impl<T: Copy + Into<Uint256>> Fraction<T> for (T, T) {
2523
}
2624

2725
fn inv(&self) -> Option<Self> {
28-
if self.numerator().into() == Uint256::zero() {
26+
if self.numerator() == 0u8.into() {
2927
None
3028
} else {
3129
Some((self.1, self.0))

0 commit comments

Comments
 (0)