@@ -30,7 +30,7 @@ use core::str::FromStr;
3030#[ cfg( feature = "std" ) ]
3131use 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
3535use num_traits:: float:: FloatCore ;
3636#[ cfg( any( feature = "std" , feature = "libm" ) ) ]
@@ -104,7 +104,9 @@ impl<T> Complex<T> {
104104}
105105
106106impl < T : Clone + Num > Complex < T > {
107- /// Returns imaginary unit
107+ /// Returns the imaginary unit.
108+ ///
109+ /// See also [`Complex::I`].
108110 #[ inline]
109111 pub fn i ( ) -> Self {
110112 Self :: new ( T :: zero ( ) , T :: one ( ) )
@@ -1146,6 +1148,15 @@ impl<T: Clone + Num> Rem<T> for Complex<T> {
11461148real_arithmetic ! ( usize , u8 , u16 , u32 , u64 , u128 , isize , i8 , i16 , i32 , i64 , i128 , f32 , f64 ) ;
11471149
11481150// constants
1151+ impl < T : ConstZero > Complex < T > {
1152+ /// A constant `Complex` 0.
1153+ pub const ZERO : Self = Self :: new ( T :: ZERO , T :: ZERO ) ;
1154+ }
1155+
1156+ impl < T : Clone + Num + ConstZero > ConstZero for Complex < T > {
1157+ const ZERO : Self = Self :: ZERO ;
1158+ }
1159+
11491160impl < T : Clone + Num > Zero for Complex < T > {
11501161 #[ inline]
11511162 fn zero ( ) -> Self {
@@ -1164,6 +1175,18 @@ impl<T: Clone + Num> Zero for Complex<T> {
11641175 }
11651176}
11661177
1178+ impl < T : ConstOne + ConstZero > Complex < T > {
1179+ /// A constant `Complex` 1.
1180+ pub const ONE : Self = Self :: new ( T :: ONE , T :: ZERO ) ;
1181+
1182+ /// A constant `Complex` _i_, the imaginary unit.
1183+ pub const I : Self = Self :: new ( T :: ZERO , T :: ONE ) ;
1184+ }
1185+
1186+ impl < T : Clone + Num + ConstOne + ConstZero > ConstOne for Complex < T > {
1187+ const ONE : Self = Self :: ONE ;
1188+ }
1189+
11671190impl < T : Clone + Num > One for Complex < T > {
11681191 #[ inline]
11691192 fn one ( ) -> Self {
0 commit comments