File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed
Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ use core::ops::Mul;
22
33pub trait Square : Mul + Copy
44{
5- type Output : Sized + From < < Self as Mul > :: Output > ;
5+ type Output : Sized ;
66
77 fn square ( & self ) -> <Self as Square >:: Output ;
88}
@@ -15,19 +15,23 @@ where
1515
1616 default fn square ( & self ) -> <Self as Square >:: Output
1717 {
18- ( * self * * self ) . into ( )
18+ unsafe {
19+ core:: intrinsics:: transmute_unchecked ( * self * * self )
20+ }
1921 }
2022}
2123
2224#[ cfg( feature = "num" ) ]
2325impl < T > Square for T
2426where
25- T : num_complex:: ComplexFloat < Real : From < T > >
27+ T : num_complex:: ComplexFloat
2628{
2729 type Output = T :: Real ;
2830
2931 fn square ( & self ) -> <Self as Square >:: Output
3032 {
31- ( * self * self . conj ( ) ) . into ( )
33+ let re = self . re ( ) ;
34+ let im = self . im ( ) ;
35+ re* re + im* im
3236 }
3337}
You can’t perform that action at this time.
0 commit comments