4
4
5
5
use core:: ops:: Neg ;
6
6
7
- use num_traits:: { float :: FloatCore , Float , FloatConst , Num , NumCast , Signed } ;
7
+ use num_traits:: { Float , FloatConst , Num , NumCast } ;
8
8
9
9
use crate :: Complex ;
10
10
11
11
mod private {
12
- use num_traits:: { float :: FloatCore , Float , FloatConst , Signed } ;
12
+ use num_traits:: { Float , FloatConst } ;
13
13
14
14
use crate :: Complex ;
15
15
16
16
pub trait Seal { }
17
17
18
18
impl < T > Seal for T where T : Float + FloatConst { }
19
- impl < T : Float + FloatCore + FloatConst + Signed > Seal for Complex < T > { }
19
+ impl < T : Float + FloatConst > Seal for Complex < T > { }
20
20
}
21
21
22
22
/// Generic trait for floating point complex numbers
@@ -235,7 +235,7 @@ where
235
235
}
236
236
}
237
237
238
- impl < T : Float + FloatCore + FloatConst + Signed > ComplexFloat for Complex < T > {
238
+ impl < T : Float + FloatConst > ComplexFloat for Complex < T > {
239
239
type Real = T ;
240
240
241
241
fn re ( self ) -> Self :: Real {
@@ -254,8 +254,28 @@ impl<T: Float + FloatCore + FloatConst + Signed> ComplexFloat for Complex<T> {
254
254
self . finv ( )
255
255
}
256
256
257
+ // `Complex::l1_norm` uses `Signed::abs` to let it work
258
+ // for integers too, but we can just use `Float::abs`.
257
259
fn l1_norm ( & self ) -> Self :: Real {
258
- Complex :: l1_norm ( self )
260
+ self . re . abs ( ) + self . im . abs ( )
261
+ }
262
+
263
+ // `Complex::is_*` methods use `T: FloatCore`, but we
264
+ // have `T: Float` that can do them as well.
265
+ fn is_nan ( self ) -> bool {
266
+ self . re . is_nan ( ) || self . im . is_nan ( )
267
+ }
268
+
269
+ fn is_infinite ( self ) -> bool {
270
+ !self . is_nan ( ) && ( self . re . is_infinite ( ) || self . im . is_infinite ( ) )
271
+ }
272
+
273
+ fn is_finite ( self ) -> bool {
274
+ self . re . is_finite ( ) && self . im . is_finite ( )
275
+ }
276
+
277
+ fn is_normal ( self ) -> bool {
278
+ self . re . is_normal ( ) && self . im . is_normal ( )
259
279
}
260
280
261
281
forward ! {
@@ -265,10 +285,6 @@ impl<T: Float + FloatCore + FloatConst + Signed> ComplexFloat for Complex<T> {
265
285
Complex :: log( self , base: Self :: Real ) -> Self ;
266
286
Complex :: log2( self ) -> Self ;
267
287
Complex :: log10( self ) -> Self ;
268
- Complex :: is_normal( self ) -> bool ;
269
- Complex :: is_infinite( self ) -> bool ;
270
- Complex :: is_finite( self ) -> bool ;
271
- Complex :: is_nan( self ) -> bool ;
272
288
Complex :: powf( self , f: Self :: Real ) -> Self ;
273
289
Complex :: sqrt( self ) -> Self ;
274
290
Complex :: cbrt( self ) -> Self ;
0 commit comments