From 7ae5235c3b1f710252fe98f34e41467904b3ed7b Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Tue, 7 May 2024 12:14:00 -0700 Subject: [PATCH 1/2] Add const ZERO/ONE and impl ConstZero/ConstOne --- Cargo.toml | 2 +- src/lib.rs | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) 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..bfbe5b1 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"))] @@ -1146,6 +1146,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 +1173,15 @@ impl Zero for Complex { } } +impl Complex { + /// A constant `Complex` 1. + pub const ONE: Self = Self::new(T::ONE, T::ZERO); +} + +impl ConstOne for Complex { + const ONE: Self = Self::ONE; +} + impl One for Complex { #[inline] fn one() -> Self { From 2045f2dcee13723bc6e6d61836126cbcbf47c15f Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Tue, 7 May 2024 12:17:01 -0700 Subject: [PATCH 2/2] Add const I --- src/lib.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index bfbe5b1..8716712 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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()) @@ -1176,6 +1178,9 @@ 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 {