Skip to content

Commit 33c9385

Browse files
authored
Merge pull request #128 from cuviper/const
Add `const ZERO`/`ONE` and `impl ConstZero`/`ConstOne`
2 parents e580ced + 2fb828a commit 33c9385

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ default-features = false
3030
features = ["i128"]
3131

3232
[dependencies.num-traits]
33-
version = "0.2.11"
33+
version = "0.2.18"
3434
default-features = false
3535
features = ["i128"]
3636

src/lib.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ use num_bigint::{BigInt, BigUint, Sign, ToBigInt};
4242
use num_integer::Integer;
4343
use num_traits::float::FloatCore;
4444
use num_traits::{
45-
Bounded, CheckedAdd, CheckedDiv, CheckedMul, CheckedSub, FromPrimitive, Inv, Num, NumCast, One,
46-
Pow, Signed, ToPrimitive, Unsigned, Zero,
45+
Bounded, CheckedAdd, CheckedDiv, CheckedMul, CheckedSub, ConstOne, ConstZero, FromPrimitive,
46+
Inv, Num, NumCast, One, Pow, Signed, ToPrimitive, Unsigned, Zero,
4747
};
4848

4949
mod pow;
@@ -922,6 +922,15 @@ where
922922
}
923923

924924
// Constants
925+
impl<T: ConstZero + ConstOne> Ratio<T> {
926+
/// A constant `Ratio` 0/1.
927+
pub const ZERO: Self = Self::new_raw(T::ZERO, T::ONE);
928+
}
929+
930+
impl<T: Clone + Integer + ConstZero + ConstOne> ConstZero for Ratio<T> {
931+
const ZERO: Self = Self::ZERO;
932+
}
933+
925934
impl<T: Clone + Integer> Zero for Ratio<T> {
926935
#[inline]
927936
fn zero() -> Ratio<T> {
@@ -940,6 +949,15 @@ impl<T: Clone + Integer> Zero for Ratio<T> {
940949
}
941950
}
942951

952+
impl<T: ConstOne> Ratio<T> {
953+
/// A constant `Ratio` 1/1.
954+
pub const ONE: Self = Self::new_raw(T::ONE, T::ONE);
955+
}
956+
957+
impl<T: Clone + Integer + ConstOne> ConstOne for Ratio<T> {
958+
const ONE: Self = Self::ONE;
959+
}
960+
943961
impl<T: Clone + Integer> One for Ratio<T> {
944962
#[inline]
945963
fn one() -> Ratio<T> {

0 commit comments

Comments
 (0)