Skip to content

Commit 7ae5235

Browse files
committed
Add const ZERO/ONE and impl ConstZero/ConstOne
1 parent f66164b commit 7ae5235

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ optional = true
2424
version = "1"
2525

2626
[dependencies.num-traits]
27-
version = "0.2.11"
27+
version = "0.2.18"
2828
default-features = false
2929
features = ["i128"]
3030

src/lib.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use core::str::FromStr;
3030
#[cfg(feature = "std")]
3131
use std::error::Error;
3232

33-
use num_traits::{Inv, MulAdd, Num, One, Pow, Signed, Zero};
33+
use num_traits::{ConstOne, ConstZero, Inv, MulAdd, Num, One, Pow, Signed, Zero};
3434

3535
use num_traits::float::FloatCore;
3636
#[cfg(any(feature = "std", feature = "libm"))]
@@ -1146,6 +1146,15 @@ impl<T: Clone + Num> Rem<T> for Complex<T> {
11461146
real_arithmetic!(usize, u8, u16, u32, u64, u128, isize, i8, i16, i32, i64, i128, f32, f64);
11471147

11481148
// constants
1149+
impl<T: ConstZero> Complex<T> {
1150+
/// A constant `Complex` 0.
1151+
pub const ZERO: Self = Self::new(T::ZERO, T::ZERO);
1152+
}
1153+
1154+
impl<T: Clone + Num + ConstZero> ConstZero for Complex<T> {
1155+
const ZERO: Self = Self::ZERO;
1156+
}
1157+
11491158
impl<T: Clone + Num> Zero for Complex<T> {
11501159
#[inline]
11511160
fn zero() -> Self {
@@ -1164,6 +1173,15 @@ impl<T: Clone + Num> Zero for Complex<T> {
11641173
}
11651174
}
11661175

1176+
impl<T: ConstOne + ConstZero> Complex<T> {
1177+
/// A constant `Complex` 1.
1178+
pub const ONE: Self = Self::new(T::ONE, T::ZERO);
1179+
}
1180+
1181+
impl<T: Clone + Num + ConstOne + ConstZero> ConstOne for Complex<T> {
1182+
const ONE: Self = Self::ONE;
1183+
}
1184+
11671185
impl<T: Clone + Num> One for Complex<T> {
11681186
#[inline]
11691187
fn one() -> Self {

0 commit comments

Comments
 (0)