3030
3131#include <math.h>
3232
33- /// \module cmath - mathematical functions for complex numbers
34- ///
35- /// The `cmath` module provides some basic mathematical funtions for
36- /// working with complex numbers.
37-
38- /// \function phase(z)
39- /// Returns the phase of the number `z`, in the range (-pi, +pi].
33+ // phase(z): returns the phase of the number z in the range (-pi, +pi]
4034STATIC mp_obj_t mp_cmath_phase (mp_obj_t z_obj ) {
4135 mp_float_t real , imag ;
4236 mp_obj_get_complex (z_obj , & real , & imag );
4337 return mp_obj_new_float (MICROPY_FLOAT_C_FUN (atan2 )(imag , real ));
4438}
4539STATIC MP_DEFINE_CONST_FUN_OBJ_1 (mp_cmath_phase_obj , mp_cmath_phase );
4640
47- /// \function polar(z)
48- /// Returns, as a tuple, the polar form of `z`.
41+ // polar(z): returns the polar form of z as a tuple
4942STATIC mp_obj_t mp_cmath_polar (mp_obj_t z_obj ) {
5043 mp_float_t real , imag ;
5144 mp_obj_get_complex (z_obj , & real , & imag );
@@ -57,17 +50,15 @@ STATIC mp_obj_t mp_cmath_polar(mp_obj_t z_obj) {
5750}
5851STATIC MP_DEFINE_CONST_FUN_OBJ_1 (mp_cmath_polar_obj , mp_cmath_polar );
5952
60- /// \function rect(r, phi)
61- /// Returns the complex number with modulus `r` and phase `phi`.
53+ // rect(r, phi): returns the complex number with modulus r and phase phi
6254STATIC mp_obj_t mp_cmath_rect (mp_obj_t r_obj , mp_obj_t phi_obj ) {
6355 mp_float_t r = mp_obj_get_float (r_obj );
6456 mp_float_t phi = mp_obj_get_float (phi_obj );
6557 return mp_obj_new_complex (r * MICROPY_FLOAT_C_FUN (cos )(phi ), r * MICROPY_FLOAT_C_FUN (sin )(phi ));
6658}
6759STATIC MP_DEFINE_CONST_FUN_OBJ_2 (mp_cmath_rect_obj , mp_cmath_rect );
6860
69- /// \function exp(z)
70- /// Return the exponential of `z`.
61+ // exp(z): return the exponential of z
7162STATIC mp_obj_t mp_cmath_exp (mp_obj_t z_obj ) {
7263 mp_float_t real , imag ;
7364 mp_obj_get_complex (z_obj , & real , & imag );
@@ -76,8 +67,7 @@ STATIC mp_obj_t mp_cmath_exp(mp_obj_t z_obj) {
7667}
7768STATIC MP_DEFINE_CONST_FUN_OBJ_1 (mp_cmath_exp_obj , mp_cmath_exp );
7869
79- /// \function log(z)
80- /// Return the natural logarithm of `z`. The branch cut is along the negative real axis.
70+ // log(z): return the natural logarithm of z, with branch cut along the negative real axis
8171// TODO can take second argument, being the base
8272STATIC mp_obj_t mp_cmath_log (mp_obj_t z_obj ) {
8373 mp_float_t real , imag ;
@@ -87,8 +77,7 @@ STATIC mp_obj_t mp_cmath_log(mp_obj_t z_obj) {
8777STATIC MP_DEFINE_CONST_FUN_OBJ_1 (mp_cmath_log_obj , mp_cmath_log );
8878
8979#if MICROPY_PY_MATH_SPECIAL_FUNCTIONS
90- /// \function log10(z)
91- /// Return the base-10 logarithm of `z`. The branch cut is along the negative real axis.
80+ // log10(z): return the base-10 logarithm of z, with branch cut along the negative real axis
9281STATIC mp_obj_t mp_cmath_log10 (mp_obj_t z_obj ) {
9382 mp_float_t real , imag ;
9483 mp_obj_get_complex (z_obj , & real , & imag );
@@ -97,8 +86,7 @@ STATIC mp_obj_t mp_cmath_log10(mp_obj_t z_obj) {
9786STATIC MP_DEFINE_CONST_FUN_OBJ_1 (mp_cmath_log10_obj , mp_cmath_log10 );
9887#endif
9988
100- /// \function sqrt(z)
101- /// Return the square-root of `z`.
89+ // sqrt(z): return the square-root of z
10290STATIC mp_obj_t mp_cmath_sqrt (mp_obj_t z_obj ) {
10391 mp_float_t real , imag ;
10492 mp_obj_get_complex (z_obj , & real , & imag );
@@ -108,17 +96,15 @@ STATIC mp_obj_t mp_cmath_sqrt(mp_obj_t z_obj) {
10896}
10997STATIC MP_DEFINE_CONST_FUN_OBJ_1 (mp_cmath_sqrt_obj , mp_cmath_sqrt );
11098
111- /// \function cos(z)
112- /// Return the cosine of `z`.
99+ // cos(z): return the cosine of z
113100STATIC mp_obj_t mp_cmath_cos (mp_obj_t z_obj ) {
114101 mp_float_t real , imag ;
115102 mp_obj_get_complex (z_obj , & real , & imag );
116103 return mp_obj_new_complex (MICROPY_FLOAT_C_FUN (cos )(real ) * MICROPY_FLOAT_C_FUN (cosh )(imag ), - MICROPY_FLOAT_C_FUN (sin )(real ) * MICROPY_FLOAT_C_FUN (sinh )(imag ));
117104}
118105STATIC MP_DEFINE_CONST_FUN_OBJ_1 (mp_cmath_cos_obj , mp_cmath_cos );
119106
120- /// \function sin(z)
121- /// Return the sine of `z`.
107+ // sin(z): return the sine of z
122108STATIC mp_obj_t mp_cmath_sin (mp_obj_t z_obj ) {
123109 mp_float_t real , imag ;
124110 mp_obj_get_complex (z_obj , & real , & imag );
0 commit comments