@@ -87,6 +87,10 @@ pub fn into_scalar<T: Scalar>(f: f64) -> T {
87
87
pub trait AssociatedReal : Sized {
88
88
type Real : RealScalar ;
89
89
fn inject ( Self :: Real ) -> Self ;
90
+ /// Returns the real part of `self`.
91
+ fn real ( self ) -> Self :: Real ;
92
+ /// Returns the imaginary part of `self`.
93
+ fn imag ( self ) -> Self :: Real ;
90
94
fn add_real ( self , Self :: Real ) -> Self ;
91
95
fn sub_real ( self , Self :: Real ) -> Self ;
92
96
fn mul_real ( self , Self :: Real ) -> Self ;
@@ -141,6 +145,8 @@ macro_rules! impl_traits {
141
145
impl AssociatedReal for $real {
142
146
type Real = $real;
143
147
fn inject( r: Self :: Real ) -> Self { r }
148
+ fn real( self ) -> Self :: Real { self }
149
+ fn imag( self ) -> Self :: Real { 0. }
144
150
fn add_real( self , r: Self :: Real ) -> Self { self + r }
145
151
fn sub_real( self , r: Self :: Real ) -> Self { self - r }
146
152
fn mul_real( self , r: Self :: Real ) -> Self { self * r }
@@ -150,6 +156,8 @@ impl AssociatedReal for $real {
150
156
impl AssociatedReal for $complex {
151
157
type Real = $real;
152
158
fn inject( r: Self :: Real ) -> Self { Self :: new( r, 0.0 ) }
159
+ fn real( self ) -> Self :: Real { self . re }
160
+ fn imag( self ) -> Self :: Real { self . im }
153
161
fn add_real( self , r: Self :: Real ) -> Self { self + r }
154
162
fn sub_real( self , r: Self :: Real ) -> Self { self - r }
155
163
fn mul_real( self , r: Self :: Real ) -> Self { self * r }
0 commit comments