• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4 
5 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6 #  include "pycore_gc.h"          // PyGC_Head
7 #  include "pycore_runtime.h"     // _Py_ID()
8 #endif
9 #include "pycore_modsupport.h"    // _PyArg_CheckPositional()
10 
11 PyDoc_STRVAR(cmath_acos__doc__,
12 "acos($module, z, /)\n"
13 "--\n"
14 "\n"
15 "Return the arc cosine of z.");
16 
17 #define CMATH_ACOS_METHODDEF    \
18     {"acos", (PyCFunction)cmath_acos, METH_O, cmath_acos__doc__},
19 
20 static Py_complex
21 cmath_acos_impl(PyObject *module, Py_complex z);
22 
23 static PyObject *
cmath_acos(PyObject * module,PyObject * arg)24 cmath_acos(PyObject *module, PyObject *arg)
25 {
26     PyObject *return_value = NULL;
27     Py_complex z;
28     Py_complex _return_value;
29 
30     z = PyComplex_AsCComplex(arg);
31     if (PyErr_Occurred()) {
32         goto exit;
33     }
34     /* modifications for z */
35     errno = 0;
36     _return_value = cmath_acos_impl(module, z);
37     if (errno == EDOM) {
38         PyErr_SetString(PyExc_ValueError, "math domain error");
39         goto exit;
40     }
41     else if (errno == ERANGE) {
42         PyErr_SetString(PyExc_OverflowError, "math range error");
43         goto exit;
44     }
45     else {
46         return_value = PyComplex_FromCComplex(_return_value);
47     }
48 
49 exit:
50     return return_value;
51 }
52 
53 PyDoc_STRVAR(cmath_acosh__doc__,
54 "acosh($module, z, /)\n"
55 "--\n"
56 "\n"
57 "Return the inverse hyperbolic cosine of z.");
58 
59 #define CMATH_ACOSH_METHODDEF    \
60     {"acosh", (PyCFunction)cmath_acosh, METH_O, cmath_acosh__doc__},
61 
62 static Py_complex
63 cmath_acosh_impl(PyObject *module, Py_complex z);
64 
65 static PyObject *
cmath_acosh(PyObject * module,PyObject * arg)66 cmath_acosh(PyObject *module, PyObject *arg)
67 {
68     PyObject *return_value = NULL;
69     Py_complex z;
70     Py_complex _return_value;
71 
72     z = PyComplex_AsCComplex(arg);
73     if (PyErr_Occurred()) {
74         goto exit;
75     }
76     /* modifications for z */
77     errno = 0;
78     _return_value = cmath_acosh_impl(module, z);
79     if (errno == EDOM) {
80         PyErr_SetString(PyExc_ValueError, "math domain error");
81         goto exit;
82     }
83     else if (errno == ERANGE) {
84         PyErr_SetString(PyExc_OverflowError, "math range error");
85         goto exit;
86     }
87     else {
88         return_value = PyComplex_FromCComplex(_return_value);
89     }
90 
91 exit:
92     return return_value;
93 }
94 
95 PyDoc_STRVAR(cmath_asin__doc__,
96 "asin($module, z, /)\n"
97 "--\n"
98 "\n"
99 "Return the arc sine of z.");
100 
101 #define CMATH_ASIN_METHODDEF    \
102     {"asin", (PyCFunction)cmath_asin, METH_O, cmath_asin__doc__},
103 
104 static Py_complex
105 cmath_asin_impl(PyObject *module, Py_complex z);
106 
107 static PyObject *
cmath_asin(PyObject * module,PyObject * arg)108 cmath_asin(PyObject *module, PyObject *arg)
109 {
110     PyObject *return_value = NULL;
111     Py_complex z;
112     Py_complex _return_value;
113 
114     z = PyComplex_AsCComplex(arg);
115     if (PyErr_Occurred()) {
116         goto exit;
117     }
118     /* modifications for z */
119     errno = 0;
120     _return_value = cmath_asin_impl(module, z);
121     if (errno == EDOM) {
122         PyErr_SetString(PyExc_ValueError, "math domain error");
123         goto exit;
124     }
125     else if (errno == ERANGE) {
126         PyErr_SetString(PyExc_OverflowError, "math range error");
127         goto exit;
128     }
129     else {
130         return_value = PyComplex_FromCComplex(_return_value);
131     }
132 
133 exit:
134     return return_value;
135 }
136 
137 PyDoc_STRVAR(cmath_asinh__doc__,
138 "asinh($module, z, /)\n"
139 "--\n"
140 "\n"
141 "Return the inverse hyperbolic sine of z.");
142 
143 #define CMATH_ASINH_METHODDEF    \
144     {"asinh", (PyCFunction)cmath_asinh, METH_O, cmath_asinh__doc__},
145 
146 static Py_complex
147 cmath_asinh_impl(PyObject *module, Py_complex z);
148 
149 static PyObject *
cmath_asinh(PyObject * module,PyObject * arg)150 cmath_asinh(PyObject *module, PyObject *arg)
151 {
152     PyObject *return_value = NULL;
153     Py_complex z;
154     Py_complex _return_value;
155 
156     z = PyComplex_AsCComplex(arg);
157     if (PyErr_Occurred()) {
158         goto exit;
159     }
160     /* modifications for z */
161     errno = 0;
162     _return_value = cmath_asinh_impl(module, z);
163     if (errno == EDOM) {
164         PyErr_SetString(PyExc_ValueError, "math domain error");
165         goto exit;
166     }
167     else if (errno == ERANGE) {
168         PyErr_SetString(PyExc_OverflowError, "math range error");
169         goto exit;
170     }
171     else {
172         return_value = PyComplex_FromCComplex(_return_value);
173     }
174 
175 exit:
176     return return_value;
177 }
178 
179 PyDoc_STRVAR(cmath_atan__doc__,
180 "atan($module, z, /)\n"
181 "--\n"
182 "\n"
183 "Return the arc tangent of z.");
184 
185 #define CMATH_ATAN_METHODDEF    \
186     {"atan", (PyCFunction)cmath_atan, METH_O, cmath_atan__doc__},
187 
188 static Py_complex
189 cmath_atan_impl(PyObject *module, Py_complex z);
190 
191 static PyObject *
cmath_atan(PyObject * module,PyObject * arg)192 cmath_atan(PyObject *module, PyObject *arg)
193 {
194     PyObject *return_value = NULL;
195     Py_complex z;
196     Py_complex _return_value;
197 
198     z = PyComplex_AsCComplex(arg);
199     if (PyErr_Occurred()) {
200         goto exit;
201     }
202     /* modifications for z */
203     errno = 0;
204     _return_value = cmath_atan_impl(module, z);
205     if (errno == EDOM) {
206         PyErr_SetString(PyExc_ValueError, "math domain error");
207         goto exit;
208     }
209     else if (errno == ERANGE) {
210         PyErr_SetString(PyExc_OverflowError, "math range error");
211         goto exit;
212     }
213     else {
214         return_value = PyComplex_FromCComplex(_return_value);
215     }
216 
217 exit:
218     return return_value;
219 }
220 
221 PyDoc_STRVAR(cmath_atanh__doc__,
222 "atanh($module, z, /)\n"
223 "--\n"
224 "\n"
225 "Return the inverse hyperbolic tangent of z.");
226 
227 #define CMATH_ATANH_METHODDEF    \
228     {"atanh", (PyCFunction)cmath_atanh, METH_O, cmath_atanh__doc__},
229 
230 static Py_complex
231 cmath_atanh_impl(PyObject *module, Py_complex z);
232 
233 static PyObject *
cmath_atanh(PyObject * module,PyObject * arg)234 cmath_atanh(PyObject *module, PyObject *arg)
235 {
236     PyObject *return_value = NULL;
237     Py_complex z;
238     Py_complex _return_value;
239 
240     z = PyComplex_AsCComplex(arg);
241     if (PyErr_Occurred()) {
242         goto exit;
243     }
244     /* modifications for z */
245     errno = 0;
246     _return_value = cmath_atanh_impl(module, z);
247     if (errno == EDOM) {
248         PyErr_SetString(PyExc_ValueError, "math domain error");
249         goto exit;
250     }
251     else if (errno == ERANGE) {
252         PyErr_SetString(PyExc_OverflowError, "math range error");
253         goto exit;
254     }
255     else {
256         return_value = PyComplex_FromCComplex(_return_value);
257     }
258 
259 exit:
260     return return_value;
261 }
262 
263 PyDoc_STRVAR(cmath_cos__doc__,
264 "cos($module, z, /)\n"
265 "--\n"
266 "\n"
267 "Return the cosine of z.");
268 
269 #define CMATH_COS_METHODDEF    \
270     {"cos", (PyCFunction)cmath_cos, METH_O, cmath_cos__doc__},
271 
272 static Py_complex
273 cmath_cos_impl(PyObject *module, Py_complex z);
274 
275 static PyObject *
cmath_cos(PyObject * module,PyObject * arg)276 cmath_cos(PyObject *module, PyObject *arg)
277 {
278     PyObject *return_value = NULL;
279     Py_complex z;
280     Py_complex _return_value;
281 
282     z = PyComplex_AsCComplex(arg);
283     if (PyErr_Occurred()) {
284         goto exit;
285     }
286     /* modifications for z */
287     errno = 0;
288     _return_value = cmath_cos_impl(module, z);
289     if (errno == EDOM) {
290         PyErr_SetString(PyExc_ValueError, "math domain error");
291         goto exit;
292     }
293     else if (errno == ERANGE) {
294         PyErr_SetString(PyExc_OverflowError, "math range error");
295         goto exit;
296     }
297     else {
298         return_value = PyComplex_FromCComplex(_return_value);
299     }
300 
301 exit:
302     return return_value;
303 }
304 
305 PyDoc_STRVAR(cmath_cosh__doc__,
306 "cosh($module, z, /)\n"
307 "--\n"
308 "\n"
309 "Return the hyperbolic cosine of z.");
310 
311 #define CMATH_COSH_METHODDEF    \
312     {"cosh", (PyCFunction)cmath_cosh, METH_O, cmath_cosh__doc__},
313 
314 static Py_complex
315 cmath_cosh_impl(PyObject *module, Py_complex z);
316 
317 static PyObject *
cmath_cosh(PyObject * module,PyObject * arg)318 cmath_cosh(PyObject *module, PyObject *arg)
319 {
320     PyObject *return_value = NULL;
321     Py_complex z;
322     Py_complex _return_value;
323 
324     z = PyComplex_AsCComplex(arg);
325     if (PyErr_Occurred()) {
326         goto exit;
327     }
328     /* modifications for z */
329     errno = 0;
330     _return_value = cmath_cosh_impl(module, z);
331     if (errno == EDOM) {
332         PyErr_SetString(PyExc_ValueError, "math domain error");
333         goto exit;
334     }
335     else if (errno == ERANGE) {
336         PyErr_SetString(PyExc_OverflowError, "math range error");
337         goto exit;
338     }
339     else {
340         return_value = PyComplex_FromCComplex(_return_value);
341     }
342 
343 exit:
344     return return_value;
345 }
346 
347 PyDoc_STRVAR(cmath_exp__doc__,
348 "exp($module, z, /)\n"
349 "--\n"
350 "\n"
351 "Return the exponential value e**z.");
352 
353 #define CMATH_EXP_METHODDEF    \
354     {"exp", (PyCFunction)cmath_exp, METH_O, cmath_exp__doc__},
355 
356 static Py_complex
357 cmath_exp_impl(PyObject *module, Py_complex z);
358 
359 static PyObject *
cmath_exp(PyObject * module,PyObject * arg)360 cmath_exp(PyObject *module, PyObject *arg)
361 {
362     PyObject *return_value = NULL;
363     Py_complex z;
364     Py_complex _return_value;
365 
366     z = PyComplex_AsCComplex(arg);
367     if (PyErr_Occurred()) {
368         goto exit;
369     }
370     /* modifications for z */
371     errno = 0;
372     _return_value = cmath_exp_impl(module, z);
373     if (errno == EDOM) {
374         PyErr_SetString(PyExc_ValueError, "math domain error");
375         goto exit;
376     }
377     else if (errno == ERANGE) {
378         PyErr_SetString(PyExc_OverflowError, "math range error");
379         goto exit;
380     }
381     else {
382         return_value = PyComplex_FromCComplex(_return_value);
383     }
384 
385 exit:
386     return return_value;
387 }
388 
389 PyDoc_STRVAR(cmath_log10__doc__,
390 "log10($module, z, /)\n"
391 "--\n"
392 "\n"
393 "Return the base-10 logarithm of z.");
394 
395 #define CMATH_LOG10_METHODDEF    \
396     {"log10", (PyCFunction)cmath_log10, METH_O, cmath_log10__doc__},
397 
398 static Py_complex
399 cmath_log10_impl(PyObject *module, Py_complex z);
400 
401 static PyObject *
cmath_log10(PyObject * module,PyObject * arg)402 cmath_log10(PyObject *module, PyObject *arg)
403 {
404     PyObject *return_value = NULL;
405     Py_complex z;
406     Py_complex _return_value;
407 
408     z = PyComplex_AsCComplex(arg);
409     if (PyErr_Occurred()) {
410         goto exit;
411     }
412     /* modifications for z */
413     errno = 0;
414     _return_value = cmath_log10_impl(module, z);
415     if (errno == EDOM) {
416         PyErr_SetString(PyExc_ValueError, "math domain error");
417         goto exit;
418     }
419     else if (errno == ERANGE) {
420         PyErr_SetString(PyExc_OverflowError, "math range error");
421         goto exit;
422     }
423     else {
424         return_value = PyComplex_FromCComplex(_return_value);
425     }
426 
427 exit:
428     return return_value;
429 }
430 
431 PyDoc_STRVAR(cmath_sin__doc__,
432 "sin($module, z, /)\n"
433 "--\n"
434 "\n"
435 "Return the sine of z.");
436 
437 #define CMATH_SIN_METHODDEF    \
438     {"sin", (PyCFunction)cmath_sin, METH_O, cmath_sin__doc__},
439 
440 static Py_complex
441 cmath_sin_impl(PyObject *module, Py_complex z);
442 
443 static PyObject *
cmath_sin(PyObject * module,PyObject * arg)444 cmath_sin(PyObject *module, PyObject *arg)
445 {
446     PyObject *return_value = NULL;
447     Py_complex z;
448     Py_complex _return_value;
449 
450     z = PyComplex_AsCComplex(arg);
451     if (PyErr_Occurred()) {
452         goto exit;
453     }
454     /* modifications for z */
455     errno = 0;
456     _return_value = cmath_sin_impl(module, z);
457     if (errno == EDOM) {
458         PyErr_SetString(PyExc_ValueError, "math domain error");
459         goto exit;
460     }
461     else if (errno == ERANGE) {
462         PyErr_SetString(PyExc_OverflowError, "math range error");
463         goto exit;
464     }
465     else {
466         return_value = PyComplex_FromCComplex(_return_value);
467     }
468 
469 exit:
470     return return_value;
471 }
472 
473 PyDoc_STRVAR(cmath_sinh__doc__,
474 "sinh($module, z, /)\n"
475 "--\n"
476 "\n"
477 "Return the hyperbolic sine of z.");
478 
479 #define CMATH_SINH_METHODDEF    \
480     {"sinh", (PyCFunction)cmath_sinh, METH_O, cmath_sinh__doc__},
481 
482 static Py_complex
483 cmath_sinh_impl(PyObject *module, Py_complex z);
484 
485 static PyObject *
cmath_sinh(PyObject * module,PyObject * arg)486 cmath_sinh(PyObject *module, PyObject *arg)
487 {
488     PyObject *return_value = NULL;
489     Py_complex z;
490     Py_complex _return_value;
491 
492     z = PyComplex_AsCComplex(arg);
493     if (PyErr_Occurred()) {
494         goto exit;
495     }
496     /* modifications for z */
497     errno = 0;
498     _return_value = cmath_sinh_impl(module, z);
499     if (errno == EDOM) {
500         PyErr_SetString(PyExc_ValueError, "math domain error");
501         goto exit;
502     }
503     else if (errno == ERANGE) {
504         PyErr_SetString(PyExc_OverflowError, "math range error");
505         goto exit;
506     }
507     else {
508         return_value = PyComplex_FromCComplex(_return_value);
509     }
510 
511 exit:
512     return return_value;
513 }
514 
515 PyDoc_STRVAR(cmath_sqrt__doc__,
516 "sqrt($module, z, /)\n"
517 "--\n"
518 "\n"
519 "Return the square root of z.");
520 
521 #define CMATH_SQRT_METHODDEF    \
522     {"sqrt", (PyCFunction)cmath_sqrt, METH_O, cmath_sqrt__doc__},
523 
524 static Py_complex
525 cmath_sqrt_impl(PyObject *module, Py_complex z);
526 
527 static PyObject *
cmath_sqrt(PyObject * module,PyObject * arg)528 cmath_sqrt(PyObject *module, PyObject *arg)
529 {
530     PyObject *return_value = NULL;
531     Py_complex z;
532     Py_complex _return_value;
533 
534     z = PyComplex_AsCComplex(arg);
535     if (PyErr_Occurred()) {
536         goto exit;
537     }
538     /* modifications for z */
539     errno = 0;
540     _return_value = cmath_sqrt_impl(module, z);
541     if (errno == EDOM) {
542         PyErr_SetString(PyExc_ValueError, "math domain error");
543         goto exit;
544     }
545     else if (errno == ERANGE) {
546         PyErr_SetString(PyExc_OverflowError, "math range error");
547         goto exit;
548     }
549     else {
550         return_value = PyComplex_FromCComplex(_return_value);
551     }
552 
553 exit:
554     return return_value;
555 }
556 
557 PyDoc_STRVAR(cmath_tan__doc__,
558 "tan($module, z, /)\n"
559 "--\n"
560 "\n"
561 "Return the tangent of z.");
562 
563 #define CMATH_TAN_METHODDEF    \
564     {"tan", (PyCFunction)cmath_tan, METH_O, cmath_tan__doc__},
565 
566 static Py_complex
567 cmath_tan_impl(PyObject *module, Py_complex z);
568 
569 static PyObject *
cmath_tan(PyObject * module,PyObject * arg)570 cmath_tan(PyObject *module, PyObject *arg)
571 {
572     PyObject *return_value = NULL;
573     Py_complex z;
574     Py_complex _return_value;
575 
576     z = PyComplex_AsCComplex(arg);
577     if (PyErr_Occurred()) {
578         goto exit;
579     }
580     /* modifications for z */
581     errno = 0;
582     _return_value = cmath_tan_impl(module, z);
583     if (errno == EDOM) {
584         PyErr_SetString(PyExc_ValueError, "math domain error");
585         goto exit;
586     }
587     else if (errno == ERANGE) {
588         PyErr_SetString(PyExc_OverflowError, "math range error");
589         goto exit;
590     }
591     else {
592         return_value = PyComplex_FromCComplex(_return_value);
593     }
594 
595 exit:
596     return return_value;
597 }
598 
599 PyDoc_STRVAR(cmath_tanh__doc__,
600 "tanh($module, z, /)\n"
601 "--\n"
602 "\n"
603 "Return the hyperbolic tangent of z.");
604 
605 #define CMATH_TANH_METHODDEF    \
606     {"tanh", (PyCFunction)cmath_tanh, METH_O, cmath_tanh__doc__},
607 
608 static Py_complex
609 cmath_tanh_impl(PyObject *module, Py_complex z);
610 
611 static PyObject *
cmath_tanh(PyObject * module,PyObject * arg)612 cmath_tanh(PyObject *module, PyObject *arg)
613 {
614     PyObject *return_value = NULL;
615     Py_complex z;
616     Py_complex _return_value;
617 
618     z = PyComplex_AsCComplex(arg);
619     if (PyErr_Occurred()) {
620         goto exit;
621     }
622     /* modifications for z */
623     errno = 0;
624     _return_value = cmath_tanh_impl(module, z);
625     if (errno == EDOM) {
626         PyErr_SetString(PyExc_ValueError, "math domain error");
627         goto exit;
628     }
629     else if (errno == ERANGE) {
630         PyErr_SetString(PyExc_OverflowError, "math range error");
631         goto exit;
632     }
633     else {
634         return_value = PyComplex_FromCComplex(_return_value);
635     }
636 
637 exit:
638     return return_value;
639 }
640 
641 PyDoc_STRVAR(cmath_log__doc__,
642 "log($module, z, base=<unrepresentable>, /)\n"
643 "--\n"
644 "\n"
645 "log(z[, base]) -> the logarithm of z to the given base.\n"
646 "\n"
647 "If the base is not specified, returns the natural logarithm (base e) of z.");
648 
649 #define CMATH_LOG_METHODDEF    \
650     {"log", _PyCFunction_CAST(cmath_log), METH_FASTCALL, cmath_log__doc__},
651 
652 static PyObject *
653 cmath_log_impl(PyObject *module, Py_complex x, PyObject *y_obj);
654 
655 static PyObject *
cmath_log(PyObject * module,PyObject * const * args,Py_ssize_t nargs)656 cmath_log(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
657 {
658     PyObject *return_value = NULL;
659     Py_complex x;
660     PyObject *y_obj = NULL;
661 
662     if (!_PyArg_CheckPositional("log", nargs, 1, 2)) {
663         goto exit;
664     }
665     x = PyComplex_AsCComplex(args[0]);
666     if (PyErr_Occurred()) {
667         goto exit;
668     }
669     if (nargs < 2) {
670         goto skip_optional;
671     }
672     y_obj = args[1];
673 skip_optional:
674     return_value = cmath_log_impl(module, x, y_obj);
675 
676 exit:
677     return return_value;
678 }
679 
680 PyDoc_STRVAR(cmath_phase__doc__,
681 "phase($module, z, /)\n"
682 "--\n"
683 "\n"
684 "Return argument, also known as the phase angle, of a complex.");
685 
686 #define CMATH_PHASE_METHODDEF    \
687     {"phase", (PyCFunction)cmath_phase, METH_O, cmath_phase__doc__},
688 
689 static PyObject *
690 cmath_phase_impl(PyObject *module, Py_complex z);
691 
692 static PyObject *
cmath_phase(PyObject * module,PyObject * arg)693 cmath_phase(PyObject *module, PyObject *arg)
694 {
695     PyObject *return_value = NULL;
696     Py_complex z;
697 
698     z = PyComplex_AsCComplex(arg);
699     if (PyErr_Occurred()) {
700         goto exit;
701     }
702     return_value = cmath_phase_impl(module, z);
703 
704 exit:
705     return return_value;
706 }
707 
708 PyDoc_STRVAR(cmath_polar__doc__,
709 "polar($module, z, /)\n"
710 "--\n"
711 "\n"
712 "Convert a complex from rectangular coordinates to polar coordinates.\n"
713 "\n"
714 "r is the distance from 0 and phi the phase angle.");
715 
716 #define CMATH_POLAR_METHODDEF    \
717     {"polar", (PyCFunction)cmath_polar, METH_O, cmath_polar__doc__},
718 
719 static PyObject *
720 cmath_polar_impl(PyObject *module, Py_complex z);
721 
722 static PyObject *
cmath_polar(PyObject * module,PyObject * arg)723 cmath_polar(PyObject *module, PyObject *arg)
724 {
725     PyObject *return_value = NULL;
726     Py_complex z;
727 
728     z = PyComplex_AsCComplex(arg);
729     if (PyErr_Occurred()) {
730         goto exit;
731     }
732     return_value = cmath_polar_impl(module, z);
733 
734 exit:
735     return return_value;
736 }
737 
738 PyDoc_STRVAR(cmath_rect__doc__,
739 "rect($module, r, phi, /)\n"
740 "--\n"
741 "\n"
742 "Convert from polar coordinates to rectangular coordinates.");
743 
744 #define CMATH_RECT_METHODDEF    \
745     {"rect", _PyCFunction_CAST(cmath_rect), METH_FASTCALL, cmath_rect__doc__},
746 
747 static PyObject *
748 cmath_rect_impl(PyObject *module, double r, double phi);
749 
750 static PyObject *
cmath_rect(PyObject * module,PyObject * const * args,Py_ssize_t nargs)751 cmath_rect(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
752 {
753     PyObject *return_value = NULL;
754     double r;
755     double phi;
756 
757     if (!_PyArg_CheckPositional("rect", nargs, 2, 2)) {
758         goto exit;
759     }
760     if (PyFloat_CheckExact(args[0])) {
761         r = PyFloat_AS_DOUBLE(args[0]);
762     }
763     else
764     {
765         r = PyFloat_AsDouble(args[0]);
766         if (r == -1.0 && PyErr_Occurred()) {
767             goto exit;
768         }
769     }
770     if (PyFloat_CheckExact(args[1])) {
771         phi = PyFloat_AS_DOUBLE(args[1]);
772     }
773     else
774     {
775         phi = PyFloat_AsDouble(args[1]);
776         if (phi == -1.0 && PyErr_Occurred()) {
777             goto exit;
778         }
779     }
780     return_value = cmath_rect_impl(module, r, phi);
781 
782 exit:
783     return return_value;
784 }
785 
786 PyDoc_STRVAR(cmath_isfinite__doc__,
787 "isfinite($module, z, /)\n"
788 "--\n"
789 "\n"
790 "Return True if both the real and imaginary parts of z are finite, else False.");
791 
792 #define CMATH_ISFINITE_METHODDEF    \
793     {"isfinite", (PyCFunction)cmath_isfinite, METH_O, cmath_isfinite__doc__},
794 
795 static PyObject *
796 cmath_isfinite_impl(PyObject *module, Py_complex z);
797 
798 static PyObject *
cmath_isfinite(PyObject * module,PyObject * arg)799 cmath_isfinite(PyObject *module, PyObject *arg)
800 {
801     PyObject *return_value = NULL;
802     Py_complex z;
803 
804     z = PyComplex_AsCComplex(arg);
805     if (PyErr_Occurred()) {
806         goto exit;
807     }
808     return_value = cmath_isfinite_impl(module, z);
809 
810 exit:
811     return return_value;
812 }
813 
814 PyDoc_STRVAR(cmath_isnan__doc__,
815 "isnan($module, z, /)\n"
816 "--\n"
817 "\n"
818 "Checks if the real or imaginary part of z not a number (NaN).");
819 
820 #define CMATH_ISNAN_METHODDEF    \
821     {"isnan", (PyCFunction)cmath_isnan, METH_O, cmath_isnan__doc__},
822 
823 static PyObject *
824 cmath_isnan_impl(PyObject *module, Py_complex z);
825 
826 static PyObject *
cmath_isnan(PyObject * module,PyObject * arg)827 cmath_isnan(PyObject *module, PyObject *arg)
828 {
829     PyObject *return_value = NULL;
830     Py_complex z;
831 
832     z = PyComplex_AsCComplex(arg);
833     if (PyErr_Occurred()) {
834         goto exit;
835     }
836     return_value = cmath_isnan_impl(module, z);
837 
838 exit:
839     return return_value;
840 }
841 
842 PyDoc_STRVAR(cmath_isinf__doc__,
843 "isinf($module, z, /)\n"
844 "--\n"
845 "\n"
846 "Checks if the real or imaginary part of z is infinite.");
847 
848 #define CMATH_ISINF_METHODDEF    \
849     {"isinf", (PyCFunction)cmath_isinf, METH_O, cmath_isinf__doc__},
850 
851 static PyObject *
852 cmath_isinf_impl(PyObject *module, Py_complex z);
853 
854 static PyObject *
cmath_isinf(PyObject * module,PyObject * arg)855 cmath_isinf(PyObject *module, PyObject *arg)
856 {
857     PyObject *return_value = NULL;
858     Py_complex z;
859 
860     z = PyComplex_AsCComplex(arg);
861     if (PyErr_Occurred()) {
862         goto exit;
863     }
864     return_value = cmath_isinf_impl(module, z);
865 
866 exit:
867     return return_value;
868 }
869 
870 PyDoc_STRVAR(cmath_isclose__doc__,
871 "isclose($module, /, a, b, *, rel_tol=1e-09, abs_tol=0.0)\n"
872 "--\n"
873 "\n"
874 "Determine whether two complex numbers are close in value.\n"
875 "\n"
876 "  rel_tol\n"
877 "    maximum difference for being considered \"close\", relative to the\n"
878 "    magnitude of the input values\n"
879 "  abs_tol\n"
880 "    maximum difference for being considered \"close\", regardless of the\n"
881 "    magnitude of the input values\n"
882 "\n"
883 "Return True if a is close in value to b, and False otherwise.\n"
884 "\n"
885 "For the values to be considered close, the difference between them must be\n"
886 "smaller than at least one of the tolerances.\n"
887 "\n"
888 "-inf, inf and NaN behave similarly to the IEEE 754 Standard. That is, NaN is\n"
889 "not close to anything, even itself. inf and -inf are only close to themselves.");
890 
891 #define CMATH_ISCLOSE_METHODDEF    \
892     {"isclose", _PyCFunction_CAST(cmath_isclose), METH_FASTCALL|METH_KEYWORDS, cmath_isclose__doc__},
893 
894 static int
895 cmath_isclose_impl(PyObject *module, Py_complex a, Py_complex b,
896                    double rel_tol, double abs_tol);
897 
898 static PyObject *
cmath_isclose(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)899 cmath_isclose(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
900 {
901     PyObject *return_value = NULL;
902     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
903 
904     #define NUM_KEYWORDS 4
905     static struct {
906         PyGC_Head _this_is_not_used;
907         PyObject_VAR_HEAD
908         PyObject *ob_item[NUM_KEYWORDS];
909     } _kwtuple = {
910         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
911         .ob_item = { _Py_LATIN1_CHR('a'), _Py_LATIN1_CHR('b'), &_Py_ID(rel_tol), &_Py_ID(abs_tol), },
912     };
913     #undef NUM_KEYWORDS
914     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
915 
916     #else  // !Py_BUILD_CORE
917     #  define KWTUPLE NULL
918     #endif  // !Py_BUILD_CORE
919 
920     static const char * const _keywords[] = {"a", "b", "rel_tol", "abs_tol", NULL};
921     static _PyArg_Parser _parser = {
922         .keywords = _keywords,
923         .fname = "isclose",
924         .kwtuple = KWTUPLE,
925     };
926     #undef KWTUPLE
927     PyObject *argsbuf[4];
928     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
929     Py_complex a;
930     Py_complex b;
931     double rel_tol = 1e-09;
932     double abs_tol = 0.0;
933     int _return_value;
934 
935     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
936     if (!args) {
937         goto exit;
938     }
939     a = PyComplex_AsCComplex(args[0]);
940     if (PyErr_Occurred()) {
941         goto exit;
942     }
943     b = PyComplex_AsCComplex(args[1]);
944     if (PyErr_Occurred()) {
945         goto exit;
946     }
947     if (!noptargs) {
948         goto skip_optional_kwonly;
949     }
950     if (args[2]) {
951         if (PyFloat_CheckExact(args[2])) {
952             rel_tol = PyFloat_AS_DOUBLE(args[2]);
953         }
954         else
955         {
956             rel_tol = PyFloat_AsDouble(args[2]);
957             if (rel_tol == -1.0 && PyErr_Occurred()) {
958                 goto exit;
959             }
960         }
961         if (!--noptargs) {
962             goto skip_optional_kwonly;
963         }
964     }
965     if (PyFloat_CheckExact(args[3])) {
966         abs_tol = PyFloat_AS_DOUBLE(args[3]);
967     }
968     else
969     {
970         abs_tol = PyFloat_AsDouble(args[3]);
971         if (abs_tol == -1.0 && PyErr_Occurred()) {
972             goto exit;
973         }
974     }
975 skip_optional_kwonly:
976     _return_value = cmath_isclose_impl(module, a, b, rel_tol, abs_tol);
977     if ((_return_value == -1) && PyErr_Occurred()) {
978         goto exit;
979     }
980     return_value = PyBool_FromLong((long)_return_value);
981 
982 exit:
983     return return_value;
984 }
985 /*[clinic end generated code: output=454309b21cfa9bf6 input=a9049054013a1b77]*/
986