44
55use core:: ops:: Neg ;
66
7- use num_traits:: { float :: FloatCore , Float , FloatConst , Num , NumCast , Signed } ;
7+ use num_traits:: { Float , FloatConst , Num , NumCast } ;
88
99use crate :: Complex ;
1010
1111mod private {
12- use num_traits:: { float :: FloatCore , Float , FloatConst , Signed } ;
12+ use num_traits:: { Float , FloatConst } ;
1313
1414 use crate :: Complex ;
1515
1616 pub trait Seal { }
1717
1818 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 > { }
2020}
2121
2222/// Generic trait for floating point complex numbers
@@ -235,7 +235,7 @@ where
235235 }
236236}
237237
238- impl < T : Float + FloatCore + FloatConst + Signed > ComplexFloat for Complex < T > {
238+ impl < T : Float + FloatConst > ComplexFloat for Complex < T > {
239239 type Real = T ;
240240
241241 fn re ( self ) -> Self :: Real {
@@ -254,8 +254,28 @@ impl<T: Float + FloatCore + FloatConst + Signed> ComplexFloat for Complex<T> {
254254 self . finv ( )
255255 }
256256
257+ // `Complex::l1_norm` uses `Signed::abs` to let it work
258+ // for integers too, but we can just use `Float::abs`.
257259 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 ( )
259279 }
260280
261281 forward ! {
@@ -265,10 +285,6 @@ impl<T: Float + FloatCore + FloatConst + Signed> ComplexFloat for Complex<T> {
265285 Complex :: log( self , base: Self :: Real ) -> Self ;
266286 Complex :: log2( self ) -> Self ;
267287 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 ;
272288 Complex :: powf( self , f: Self :: Real ) -> Self ;
273289 Complex :: sqrt( self ) -> Self ;
274290 Complex :: cbrt( self ) -> Self ;
0 commit comments