@@ -30,7 +30,7 @@ use core::str::FromStr;
30
30
#[ cfg( feature = "std" ) ]
31
31
use std:: error:: Error ;
32
32
33
- use num_traits:: { Inv , MulAdd , Num , One , Pow , Signed , Zero } ;
33
+ use num_traits:: { ConstOne , ConstZero , Inv , MulAdd , Num , One , Pow , Signed , Zero } ;
34
34
35
35
use num_traits:: float:: FloatCore ;
36
36
#[ cfg( any( feature = "std" , feature = "libm" ) ) ]
@@ -104,7 +104,9 @@ impl<T> Complex<T> {
104
104
}
105
105
106
106
impl < T : Clone + Num > Complex < T > {
107
- /// Returns imaginary unit
107
+ /// Returns the imaginary unit.
108
+ ///
109
+ /// See also [`Complex::I`].
108
110
#[ inline]
109
111
pub fn i ( ) -> Self {
110
112
Self :: new ( T :: zero ( ) , T :: one ( ) )
@@ -1146,6 +1148,15 @@ impl<T: Clone + Num> Rem<T> for Complex<T> {
1146
1148
real_arithmetic ! ( usize , u8 , u16 , u32 , u64 , u128 , isize , i8 , i16 , i32 , i64 , i128 , f32 , f64 ) ;
1147
1149
1148
1150
// 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
+
1149
1160
impl < T : Clone + Num > Zero for Complex < T > {
1150
1161
#[ inline]
1151
1162
fn zero ( ) -> Self {
@@ -1164,6 +1175,18 @@ impl<T: Clone + Num> Zero for Complex<T> {
1164
1175
}
1165
1176
}
1166
1177
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
+
1167
1190
impl < T : Clone + Num > One for Complex < T > {
1168
1191
#[ inline]
1169
1192
fn one ( ) -> Self {
0 commit comments