11// TODO: Keep track of rust-num/num-complex/issues/2. A common trait could help with duplication
22// that exists between cmath and math.
33pub ( crate ) use cmath:: make_module;
4-
5- /// This module provides access to mathematical functions for complex numbers.
64#[ pymodule]
75mod cmath {
86 use crate :: vm:: {
@@ -21,57 +19,48 @@ mod cmath {
2119 #[ pyattr( name = "nanj" ) ]
2220 const NANJ : Complex64 = Complex64 :: new ( 0. , std:: f64:: NAN ) ;
2321
24- /// Return argument, also known as the phase angle, of a complex.
2522 #[ pyfunction]
2623 fn phase ( z : ArgIntoComplex ) -> f64 {
2724 z. arg ( )
2825 }
2926
30- /// Convert a complex from rectangular coordinates to polar coordinates.
31- ///
32- /// r is the distance from 0 and phi the phase angle.
3327 #[ pyfunction]
3428 fn polar ( x : ArgIntoComplex ) -> ( f64 , f64 ) {
3529 x. to_polar ( )
3630 }
3731
38- /// Convert from polar coordinates to rectangular coordinates.
3932 #[ pyfunction]
4033 fn rect ( r : ArgIntoFloat , phi : ArgIntoFloat ) -> Complex64 {
4134 Complex64 :: from_polar ( * r, * phi)
4235 }
4336
44- /// Checks if the real or imaginary part of z is infinite.
4537 #[ pyfunction]
4638 fn isinf ( z : ArgIntoComplex ) -> bool {
4739 let Complex64 { re, im } = * z;
4840 re. is_infinite ( ) || im. is_infinite ( )
4941 }
5042
51- /// Return True if both the real and imaginary parts of z are finite, else False.
5243 #[ pyfunction]
5344 fn isfinite ( z : ArgIntoComplex ) -> bool {
5445 z. is_finite ( )
5546 }
5647
57- /// Checks if the real or imaginary part of z not a number (NaN)..
5848 #[ pyfunction]
5949 fn isnan ( z : ArgIntoComplex ) -> bool {
6050 z. is_nan ( )
6151 }
6252
63- /// Return the exponential value e**z.
6453 #[ pyfunction]
6554 fn exp ( z : ArgIntoComplex , vm : & VirtualMachine ) -> PyResult < Complex64 > {
6655 let z = * z;
6756 result_or_overflow ( z, z. exp ( ) , vm)
6857 }
69- /// Return the square root of z.
58+
7059 #[ pyfunction]
7160 fn sqrt ( z : ArgIntoComplex ) -> Complex64 {
7261 z. sqrt ( )
7362 }
74- /// Return the sine of z
63+
7564 #[ pyfunction]
7665 fn sin ( z : ArgIntoComplex ) -> Complex64 {
7766 z. sin ( )
@@ -82,7 +71,6 @@ mod cmath {
8271 z. asin ( )
8372 }
8473
85- /// Return the cosine of z
8674 #[ pyfunction]
8775 fn cos ( z : ArgIntoComplex ) -> Complex64 {
8876 z. cos ( )
@@ -93,9 +81,6 @@ mod cmath {
9381 z. acos ( )
9482 }
9583
96- /// log(z[, base]) -> the logarithm of z to the given base.
97- ///
98- /// If the base not specified, returns the natural logarithm (base e) of z.
9984 #[ pyfunction]
10085 fn log ( z : ArgIntoComplex , base : OptionalArg < ArgIntoComplex > ) -> Complex64 {
10186 // TODO: Complex64.log with a negative base yields wrong results.
@@ -110,55 +95,46 @@ mod cmath {
11095 )
11196 }
11297
113- /// Return the base-10 logarithm of z.
11498 #[ pyfunction]
11599 fn log10 ( z : ArgIntoComplex ) -> Complex64 {
116100 z. log ( 10.0 )
117101 }
118102
119- /// Return the inverse hyperbolic cosine of z.
120103 #[ pyfunction]
121104 fn acosh ( z : ArgIntoComplex ) -> Complex64 {
122105 z. acosh ( )
123106 }
124107
125- /// Return the inverse tangent of z.
126108 #[ pyfunction]
127109 fn atan ( z : ArgIntoComplex ) -> Complex64 {
128110 z. atan ( )
129111 }
130112
131- /// Return the inverse hyperbolic tangent of z.
132113 #[ pyfunction]
133114 fn atanh ( z : ArgIntoComplex ) -> Complex64 {
134115 z. atanh ( )
135116 }
136117
137- /// Return the tangent of z.
138118 #[ pyfunction]
139119 fn tan ( z : ArgIntoComplex ) -> Complex64 {
140120 z. tan ( )
141121 }
142122
143- /// Return the hyperbolic tangent of z.
144123 #[ pyfunction]
145124 fn tanh ( z : ArgIntoComplex ) -> Complex64 {
146125 z. tanh ( )
147126 }
148127
149- /// Return the hyperbolic sin of z.
150128 #[ pyfunction]
151129 fn sinh ( z : ArgIntoComplex ) -> Complex64 {
152130 z. sinh ( )
153131 }
154132
155- /// Return the hyperbolic cosine of z.
156133 #[ pyfunction]
157134 fn cosh ( z : ArgIntoComplex ) -> Complex64 {
158135 z. cosh ( )
159136 }
160137
161- /// Return the inverse hyperbolic sine of z.
162138 #[ pyfunction]
163139 fn asinh ( z : ArgIntoComplex ) -> Complex64 {
164140 z. asinh ( )
@@ -176,22 +152,6 @@ mod cmath {
176152 abs_tol : OptionalArg < ArgIntoFloat > ,
177153 }
178154
179- /// Determine whether two complex numbers are close in value.
180- ///
181- /// rel_tol
182- /// maximum difference for being considered "close", relative to the
183- /// magnitude of the input values
184- /// abs_tol
185- /// maximum difference for being considered "close", regardless of the
186- /// magnitude of the input values
187- ///
188- /// Return True if a is close in value to b, and False otherwise.
189- ///
190- /// For the values to be considered close, the difference between them must be
191- /// smaller than at least one of the tolerances.
192- ///
193- /// -inf, inf and NaN behave similarly to the IEEE 754 Standard. That is, NaN is
194- /// not close to anything, even itself. inf and -inf are only close to themselves.
195155 #[ pyfunction]
196156 fn isclose ( args : IsCloseArgs , vm : & VirtualMachine ) -> PyResult < bool > {
197157 let a = * args. a ;
0 commit comments