diff --git a/Cargo.toml b/Cargo.toml index 050537b..db5a7d6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,7 @@ optional = true version = "1" [dependencies.num-traits] -version = "0.2.11" +version = "0.2.18" default-features = false features = ["i128"] diff --git a/src/lib.rs b/src/lib.rs index 3c647e2..8716712 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -30,7 +30,7 @@ use core::str::FromStr; #[cfg(feature = "std")] use std::error::Error; -use num_traits::{Inv, MulAdd, Num, One, Pow, Signed, Zero}; +use num_traits::{ConstOne, ConstZero, Inv, MulAdd, Num, One, Pow, Signed, Zero}; use num_traits::float::FloatCore; #[cfg(any(feature = "std", feature = "libm"))] @@ -104,7 +104,9 @@ impl Complex { } impl Complex { - /// Returns imaginary unit + /// Returns the imaginary unit. + /// + /// See also [`Complex::I`]. #[inline] pub fn i() -> Self { Self::new(T::zero(), T::one()) @@ -1146,6 +1148,15 @@ impl Rem for Complex { real_arithmetic!(usize, u8, u16, u32, u64, u128, isize, i8, i16, i32, i64, i128, f32, f64); // constants +impl Complex { + /// A constant `Complex` 0. + pub const ZERO: Self = Self::new(T::ZERO, T::ZERO); +} + +impl ConstZero for Complex { + const ZERO: Self = Self::ZERO; +} + impl Zero for Complex { #[inline] fn zero() -> Self { @@ -1164,6 +1175,18 @@ impl Zero for Complex { } } +impl Complex { + /// A constant `Complex` 1. + pub const ONE: Self = Self::new(T::ONE, T::ZERO); + + /// A constant `Complex` _i_, the imaginary unit. + pub const I: Self = Self::new(T::ZERO, T::ONE); +} + +impl ConstOne for Complex { + const ONE: Self = Self::ONE; +} + impl One for Complex { #[inline] fn one() -> Self {