@@ -48,6 +48,7 @@ impl Complex {
4848 Self { re, im }
4949 }
5050 /// Get the minimum of the real and imaginary parts of two complex numbers, ignoring NaN
51+ #[ must_use]
5152 pub fn min ( self , rhs : impl Into < Self > ) -> Self {
5253 let rhs = rhs. into ( ) ;
5354 Self {
@@ -56,6 +57,7 @@ impl Complex {
5657 }
5758 }
5859 /// Get the maximum of the real and imaginary parts of two complex numbers, ignoring NaN
60+ #[ must_use]
5961 pub fn max ( self , rhs : impl Into < Self > ) -> Self {
6062 let rhs = rhs. into ( ) ;
6163 Self {
@@ -64,20 +66,23 @@ impl Complex {
6466 }
6567 }
6668 /// Get the floor of the real and imaginary parts of a complex number
69+ #[ must_use]
6770 pub fn floor ( self ) -> Self {
6871 Self {
6972 re : self . re . floor ( ) ,
7073 im : self . im . floor ( ) ,
7174 }
7275 }
7376 /// Get the ceiling of the real and imaginary parts of a complex number
77+ #[ must_use]
7478 pub fn ceil ( self ) -> Self {
7579 Self {
7680 re : self . re . ceil ( ) ,
7781 im : self . im . ceil ( ) ,
7882 }
7983 }
8084 /// Round the real and imaginary parts of a complex number
85+ #[ must_use]
8186 pub fn round ( self ) -> Self {
8287 Self {
8388 re : self . re . round ( ) ,
@@ -90,12 +95,14 @@ impl Complex {
9095 ( self . re * self . re + self . im * self . im ) . sqrt ( )
9196 }
9297 /// Get the arctangent of a complex number
98+ #[ must_use]
9399 pub fn atan2 ( self , x : impl Into < Self > ) -> Complex {
94100 let y = self ;
95101 let x = x. into ( ) ;
96102 -Complex :: I * ( ( x + Complex :: I * y) / ( y * y + x * x) . sqrt ( ) ) . ln ( )
97103 }
98104 /// Normalize a complex number
105+ #[ must_use]
99106 pub fn normalize ( self ) -> Self {
100107 let len = self . abs ( ) ;
101108 if len == 0.0 {
@@ -117,6 +124,7 @@ impl Complex {
117124 r * Self :: new ( theta. cos ( ) , theta. sin ( ) )
118125 }
119126 /// Raise a complex number to a complex power
127+ #[ must_use]
120128 pub fn powc ( self , power : impl Into < Self > ) -> Self {
121129 let power = power. into ( ) ;
122130 if power. im == 0.0 {
@@ -126,6 +134,7 @@ impl Complex {
126134 ( ( r. ln ( ) + Self :: I * theta) * power) . exp ( )
127135 }
128136 /// Raise a complex number to a real power
137+ #[ must_use]
129138 pub fn powf ( self , power : f64 ) -> Self {
130139 if power == 0.0 {
131140 return Self :: ONE ;
@@ -137,20 +146,24 @@ impl Complex {
137146 Self :: from_polar ( r. powf ( power) , theta * power)
138147 }
139148 /// Calculate the exponential of a complex number
149+ #[ must_use]
140150 pub fn exp ( self ) -> Self {
141151 Self :: from_polar ( E . powf ( self . re ) , self . im )
142152 }
143153 /// Calculate the natural logarithm of a complex number
154+ #[ must_use]
144155 pub fn ln ( self ) -> Self {
145156 let ( r, theta) = self . to_polar ( ) ;
146157 Self :: new ( r. ln ( ) , theta)
147158 }
148159 /// Calculate the logarithm of a complex number
160+ #[ must_use]
149161 pub fn log ( self , base : impl Into < Self > ) -> Self {
150162 let base = base. into ( ) ;
151163 Self :: new ( self . abs ( ) . ln ( ) , self . arg ( ) ) / ( Self :: new ( base. abs ( ) . ln ( ) , base. arg ( ) ) )
152164 }
153165 /// Calculate the square root of a complex number
166+ #[ must_use]
154167 pub fn sqrt ( self ) -> Self {
155168 if self . im == 0.0 {
156169 return if self . re >= 0.0 {
@@ -163,24 +176,28 @@ impl Complex {
163176 Self :: from_polar ( r. sqrt ( ) , theta / 2.0 )
164177 }
165178 /// Calculate the sine of a complex number
179+ #[ must_use]
166180 pub fn sin ( self ) -> Self {
167181 Self :: new (
168182 self . re . sin ( ) * self . im . cosh ( ) ,
169183 self . re . cos ( ) * self . im . sinh ( ) ,
170184 )
171185 }
172186 /// Calculate the cosine of a complex number
187+ #[ must_use]
173188 pub fn cos ( self ) -> Self {
174189 Self :: new (
175190 self . re . cos ( ) * self . im . cosh ( ) ,
176191 -self . re . sin ( ) * self . im . sinh ( ) ,
177192 )
178193 }
179194 /// Calculate the arc sine of a complex number
195+ #[ must_use]
180196 pub fn asin ( self ) -> Self {
181197 -Self :: I * ( ( Self :: ONE - self * self ) . sqrt ( ) + Self :: I * self ) . ln ( )
182198 }
183199 /// Calculate the arc cosine of a complex number
200+ #[ must_use]
184201 pub fn acos ( self ) -> Self {
185202 -Self :: I * ( Self :: I * ( Self :: ONE - self * self ) . sqrt ( ) + self ) . ln ( )
186203 }
@@ -197,13 +214,15 @@ impl Complex {
197214 }
198215 }
199216 /// Multiply by another complex number, with 0 × ∞ = 0
217+ #[ must_use]
200218 pub fn safe_mul ( self , rhs : impl Into < Self > ) -> Self {
201219 let rhs = rhs. into ( ) ;
202220 Self {
203221 re : safe_mul ( self . re , rhs. re ) - safe_mul ( self . im , rhs. im ) ,
204222 im : safe_mul ( self . re , rhs. im ) + safe_mul ( self . im , rhs. re ) ,
205223 }
206224 }
225+ #[ must_use]
207226 pub fn recip ( self ) -> Self {
208227 Self :: ONE / self
209228 }
0 commit comments