Branch data Line data Source code
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 : :
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 *
24 : 0 : cmath_acos(PyObject *module, PyObject *arg)
25 : : {
26 : 0 : PyObject *return_value = NULL;
27 : : Py_complex z;
28 : : Py_complex _return_value;
29 : :
30 : 0 : z = PyComplex_AsCComplex(arg);
31 [ # # ]: 0 : if (PyErr_Occurred()) {
32 : 0 : goto exit;
33 : : }
34 : : /* modifications for z */
35 : 0 : errno = 0;
36 : 0 : _return_value = cmath_acos_impl(module, z);
37 [ # # ]: 0 : if (errno == EDOM) {
38 : 0 : PyErr_SetString(PyExc_ValueError, "math domain error");
39 : 0 : goto exit;
40 : : }
41 [ # # ]: 0 : else if (errno == ERANGE) {
42 : 0 : PyErr_SetString(PyExc_OverflowError, "math range error");
43 : 0 : goto exit;
44 : : }
45 : : else {
46 : 0 : return_value = PyComplex_FromCComplex(_return_value);
47 : : }
48 : :
49 : 0 : exit:
50 : 0 : 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 *
66 : 0 : cmath_acosh(PyObject *module, PyObject *arg)
67 : : {
68 : 0 : PyObject *return_value = NULL;
69 : : Py_complex z;
70 : : Py_complex _return_value;
71 : :
72 : 0 : z = PyComplex_AsCComplex(arg);
73 [ # # ]: 0 : if (PyErr_Occurred()) {
74 : 0 : goto exit;
75 : : }
76 : : /* modifications for z */
77 : 0 : errno = 0;
78 : 0 : _return_value = cmath_acosh_impl(module, z);
79 [ # # ]: 0 : if (errno == EDOM) {
80 : 0 : PyErr_SetString(PyExc_ValueError, "math domain error");
81 : 0 : goto exit;
82 : : }
83 [ # # ]: 0 : else if (errno == ERANGE) {
84 : 0 : PyErr_SetString(PyExc_OverflowError, "math range error");
85 : 0 : goto exit;
86 : : }
87 : : else {
88 : 0 : return_value = PyComplex_FromCComplex(_return_value);
89 : : }
90 : :
91 : 0 : exit:
92 : 0 : 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 *
108 : 0 : cmath_asin(PyObject *module, PyObject *arg)
109 : : {
110 : 0 : PyObject *return_value = NULL;
111 : : Py_complex z;
112 : : Py_complex _return_value;
113 : :
114 : 0 : z = PyComplex_AsCComplex(arg);
115 [ # # ]: 0 : if (PyErr_Occurred()) {
116 : 0 : goto exit;
117 : : }
118 : : /* modifications for z */
119 : 0 : errno = 0;
120 : 0 : _return_value = cmath_asin_impl(module, z);
121 [ # # ]: 0 : if (errno == EDOM) {
122 : 0 : PyErr_SetString(PyExc_ValueError, "math domain error");
123 : 0 : goto exit;
124 : : }
125 [ # # ]: 0 : else if (errno == ERANGE) {
126 : 0 : PyErr_SetString(PyExc_OverflowError, "math range error");
127 : 0 : goto exit;
128 : : }
129 : : else {
130 : 0 : return_value = PyComplex_FromCComplex(_return_value);
131 : : }
132 : :
133 : 0 : exit:
134 : 0 : 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 *
150 : 0 : cmath_asinh(PyObject *module, PyObject *arg)
151 : : {
152 : 0 : PyObject *return_value = NULL;
153 : : Py_complex z;
154 : : Py_complex _return_value;
155 : :
156 : 0 : z = PyComplex_AsCComplex(arg);
157 [ # # ]: 0 : if (PyErr_Occurred()) {
158 : 0 : goto exit;
159 : : }
160 : : /* modifications for z */
161 : 0 : errno = 0;
162 : 0 : _return_value = cmath_asinh_impl(module, z);
163 [ # # ]: 0 : if (errno == EDOM) {
164 : 0 : PyErr_SetString(PyExc_ValueError, "math domain error");
165 : 0 : goto exit;
166 : : }
167 [ # # ]: 0 : else if (errno == ERANGE) {
168 : 0 : PyErr_SetString(PyExc_OverflowError, "math range error");
169 : 0 : goto exit;
170 : : }
171 : : else {
172 : 0 : return_value = PyComplex_FromCComplex(_return_value);
173 : : }
174 : :
175 : 0 : exit:
176 : 0 : 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 *
192 : 0 : cmath_atan(PyObject *module, PyObject *arg)
193 : : {
194 : 0 : PyObject *return_value = NULL;
195 : : Py_complex z;
196 : : Py_complex _return_value;
197 : :
198 : 0 : z = PyComplex_AsCComplex(arg);
199 [ # # ]: 0 : if (PyErr_Occurred()) {
200 : 0 : goto exit;
201 : : }
202 : : /* modifications for z */
203 : 0 : errno = 0;
204 : 0 : _return_value = cmath_atan_impl(module, z);
205 [ # # ]: 0 : if (errno == EDOM) {
206 : 0 : PyErr_SetString(PyExc_ValueError, "math domain error");
207 : 0 : goto exit;
208 : : }
209 [ # # ]: 0 : else if (errno == ERANGE) {
210 : 0 : PyErr_SetString(PyExc_OverflowError, "math range error");
211 : 0 : goto exit;
212 : : }
213 : : else {
214 : 0 : return_value = PyComplex_FromCComplex(_return_value);
215 : : }
216 : :
217 : 0 : exit:
218 : 0 : 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 *
234 : 0 : cmath_atanh(PyObject *module, PyObject *arg)
235 : : {
236 : 0 : PyObject *return_value = NULL;
237 : : Py_complex z;
238 : : Py_complex _return_value;
239 : :
240 : 0 : z = PyComplex_AsCComplex(arg);
241 [ # # ]: 0 : if (PyErr_Occurred()) {
242 : 0 : goto exit;
243 : : }
244 : : /* modifications for z */
245 : 0 : errno = 0;
246 : 0 : _return_value = cmath_atanh_impl(module, z);
247 [ # # ]: 0 : if (errno == EDOM) {
248 : 0 : PyErr_SetString(PyExc_ValueError, "math domain error");
249 : 0 : goto exit;
250 : : }
251 [ # # ]: 0 : else if (errno == ERANGE) {
252 : 0 : PyErr_SetString(PyExc_OverflowError, "math range error");
253 : 0 : goto exit;
254 : : }
255 : : else {
256 : 0 : return_value = PyComplex_FromCComplex(_return_value);
257 : : }
258 : :
259 : 0 : exit:
260 : 0 : 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 *
276 : 0 : cmath_cos(PyObject *module, PyObject *arg)
277 : : {
278 : 0 : PyObject *return_value = NULL;
279 : : Py_complex z;
280 : : Py_complex _return_value;
281 : :
282 : 0 : z = PyComplex_AsCComplex(arg);
283 [ # # ]: 0 : if (PyErr_Occurred()) {
284 : 0 : goto exit;
285 : : }
286 : : /* modifications for z */
287 : 0 : errno = 0;
288 : 0 : _return_value = cmath_cos_impl(module, z);
289 [ # # ]: 0 : if (errno == EDOM) {
290 : 0 : PyErr_SetString(PyExc_ValueError, "math domain error");
291 : 0 : goto exit;
292 : : }
293 [ # # ]: 0 : else if (errno == ERANGE) {
294 : 0 : PyErr_SetString(PyExc_OverflowError, "math range error");
295 : 0 : goto exit;
296 : : }
297 : : else {
298 : 0 : return_value = PyComplex_FromCComplex(_return_value);
299 : : }
300 : :
301 : 0 : exit:
302 : 0 : 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 *
318 : 0 : cmath_cosh(PyObject *module, PyObject *arg)
319 : : {
320 : 0 : PyObject *return_value = NULL;
321 : : Py_complex z;
322 : : Py_complex _return_value;
323 : :
324 : 0 : z = PyComplex_AsCComplex(arg);
325 [ # # ]: 0 : if (PyErr_Occurred()) {
326 : 0 : goto exit;
327 : : }
328 : : /* modifications for z */
329 : 0 : errno = 0;
330 : 0 : _return_value = cmath_cosh_impl(module, z);
331 [ # # ]: 0 : if (errno == EDOM) {
332 : 0 : PyErr_SetString(PyExc_ValueError, "math domain error");
333 : 0 : goto exit;
334 : : }
335 [ # # ]: 0 : else if (errno == ERANGE) {
336 : 0 : PyErr_SetString(PyExc_OverflowError, "math range error");
337 : 0 : goto exit;
338 : : }
339 : : else {
340 : 0 : return_value = PyComplex_FromCComplex(_return_value);
341 : : }
342 : :
343 : 0 : exit:
344 : 0 : 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 *
360 : 0 : cmath_exp(PyObject *module, PyObject *arg)
361 : : {
362 : 0 : PyObject *return_value = NULL;
363 : : Py_complex z;
364 : : Py_complex _return_value;
365 : :
366 : 0 : z = PyComplex_AsCComplex(arg);
367 [ # # ]: 0 : if (PyErr_Occurred()) {
368 : 0 : goto exit;
369 : : }
370 : : /* modifications for z */
371 : 0 : errno = 0;
372 : 0 : _return_value = cmath_exp_impl(module, z);
373 [ # # ]: 0 : if (errno == EDOM) {
374 : 0 : PyErr_SetString(PyExc_ValueError, "math domain error");
375 : 0 : goto exit;
376 : : }
377 [ # # ]: 0 : else if (errno == ERANGE) {
378 : 0 : PyErr_SetString(PyExc_OverflowError, "math range error");
379 : 0 : goto exit;
380 : : }
381 : : else {
382 : 0 : return_value = PyComplex_FromCComplex(_return_value);
383 : : }
384 : :
385 : 0 : exit:
386 : 0 : 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 *
402 : 0 : cmath_log10(PyObject *module, PyObject *arg)
403 : : {
404 : 0 : PyObject *return_value = NULL;
405 : : Py_complex z;
406 : : Py_complex _return_value;
407 : :
408 : 0 : z = PyComplex_AsCComplex(arg);
409 [ # # ]: 0 : if (PyErr_Occurred()) {
410 : 0 : goto exit;
411 : : }
412 : : /* modifications for z */
413 : 0 : errno = 0;
414 : 0 : _return_value = cmath_log10_impl(module, z);
415 [ # # ]: 0 : if (errno == EDOM) {
416 : 0 : PyErr_SetString(PyExc_ValueError, "math domain error");
417 : 0 : goto exit;
418 : : }
419 [ # # ]: 0 : else if (errno == ERANGE) {
420 : 0 : PyErr_SetString(PyExc_OverflowError, "math range error");
421 : 0 : goto exit;
422 : : }
423 : : else {
424 : 0 : return_value = PyComplex_FromCComplex(_return_value);
425 : : }
426 : :
427 : 0 : exit:
428 : 0 : 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 *
444 : 0 : cmath_sin(PyObject *module, PyObject *arg)
445 : : {
446 : 0 : PyObject *return_value = NULL;
447 : : Py_complex z;
448 : : Py_complex _return_value;
449 : :
450 : 0 : z = PyComplex_AsCComplex(arg);
451 [ # # ]: 0 : if (PyErr_Occurred()) {
452 : 0 : goto exit;
453 : : }
454 : : /* modifications for z */
455 : 0 : errno = 0;
456 : 0 : _return_value = cmath_sin_impl(module, z);
457 [ # # ]: 0 : if (errno == EDOM) {
458 : 0 : PyErr_SetString(PyExc_ValueError, "math domain error");
459 : 0 : goto exit;
460 : : }
461 [ # # ]: 0 : else if (errno == ERANGE) {
462 : 0 : PyErr_SetString(PyExc_OverflowError, "math range error");
463 : 0 : goto exit;
464 : : }
465 : : else {
466 : 0 : return_value = PyComplex_FromCComplex(_return_value);
467 : : }
468 : :
469 : 0 : exit:
470 : 0 : 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 *
486 : 0 : cmath_sinh(PyObject *module, PyObject *arg)
487 : : {
488 : 0 : PyObject *return_value = NULL;
489 : : Py_complex z;
490 : : Py_complex _return_value;
491 : :
492 : 0 : z = PyComplex_AsCComplex(arg);
493 [ # # ]: 0 : if (PyErr_Occurred()) {
494 : 0 : goto exit;
495 : : }
496 : : /* modifications for z */
497 : 0 : errno = 0;
498 : 0 : _return_value = cmath_sinh_impl(module, z);
499 [ # # ]: 0 : if (errno == EDOM) {
500 : 0 : PyErr_SetString(PyExc_ValueError, "math domain error");
501 : 0 : goto exit;
502 : : }
503 [ # # ]: 0 : else if (errno == ERANGE) {
504 : 0 : PyErr_SetString(PyExc_OverflowError, "math range error");
505 : 0 : goto exit;
506 : : }
507 : : else {
508 : 0 : return_value = PyComplex_FromCComplex(_return_value);
509 : : }
510 : :
511 : 0 : exit:
512 : 0 : 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 *
528 : 0 : cmath_sqrt(PyObject *module, PyObject *arg)
529 : : {
530 : 0 : PyObject *return_value = NULL;
531 : : Py_complex z;
532 : : Py_complex _return_value;
533 : :
534 : 0 : z = PyComplex_AsCComplex(arg);
535 [ # # ]: 0 : if (PyErr_Occurred()) {
536 : 0 : goto exit;
537 : : }
538 : : /* modifications for z */
539 : 0 : errno = 0;
540 : 0 : _return_value = cmath_sqrt_impl(module, z);
541 [ # # ]: 0 : if (errno == EDOM) {
542 : 0 : PyErr_SetString(PyExc_ValueError, "math domain error");
543 : 0 : goto exit;
544 : : }
545 [ # # ]: 0 : else if (errno == ERANGE) {
546 : 0 : PyErr_SetString(PyExc_OverflowError, "math range error");
547 : 0 : goto exit;
548 : : }
549 : : else {
550 : 0 : return_value = PyComplex_FromCComplex(_return_value);
551 : : }
552 : :
553 : 0 : exit:
554 : 0 : 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 *
570 : 0 : cmath_tan(PyObject *module, PyObject *arg)
571 : : {
572 : 0 : PyObject *return_value = NULL;
573 : : Py_complex z;
574 : : Py_complex _return_value;
575 : :
576 : 0 : z = PyComplex_AsCComplex(arg);
577 [ # # ]: 0 : if (PyErr_Occurred()) {
578 : 0 : goto exit;
579 : : }
580 : : /* modifications for z */
581 : 0 : errno = 0;
582 : 0 : _return_value = cmath_tan_impl(module, z);
583 [ # # ]: 0 : if (errno == EDOM) {
584 : 0 : PyErr_SetString(PyExc_ValueError, "math domain error");
585 : 0 : goto exit;
586 : : }
587 [ # # ]: 0 : else if (errno == ERANGE) {
588 : 0 : PyErr_SetString(PyExc_OverflowError, "math range error");
589 : 0 : goto exit;
590 : : }
591 : : else {
592 : 0 : return_value = PyComplex_FromCComplex(_return_value);
593 : : }
594 : :
595 : 0 : exit:
596 : 0 : 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 *
612 : 0 : cmath_tanh(PyObject *module, PyObject *arg)
613 : : {
614 : 0 : PyObject *return_value = NULL;
615 : : Py_complex z;
616 : : Py_complex _return_value;
617 : :
618 : 0 : z = PyComplex_AsCComplex(arg);
619 [ # # ]: 0 : if (PyErr_Occurred()) {
620 : 0 : goto exit;
621 : : }
622 : : /* modifications for z */
623 : 0 : errno = 0;
624 : 0 : _return_value = cmath_tanh_impl(module, z);
625 [ # # ]: 0 : if (errno == EDOM) {
626 : 0 : PyErr_SetString(PyExc_ValueError, "math domain error");
627 : 0 : goto exit;
628 : : }
629 [ # # ]: 0 : else if (errno == ERANGE) {
630 : 0 : PyErr_SetString(PyExc_OverflowError, "math range error");
631 : 0 : goto exit;
632 : : }
633 : : else {
634 : 0 : return_value = PyComplex_FromCComplex(_return_value);
635 : : }
636 : :
637 : 0 : exit:
638 : 0 : 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 *
656 : 0 : cmath_log(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
657 : : {
658 : 0 : PyObject *return_value = NULL;
659 : : Py_complex x;
660 : 0 : PyObject *y_obj = NULL;
661 : :
662 [ # # # # : 0 : if (!_PyArg_CheckPositional("log", nargs, 1, 2)) {
# # ]
663 : 0 : goto exit;
664 : : }
665 : 0 : x = PyComplex_AsCComplex(args[0]);
666 [ # # ]: 0 : if (PyErr_Occurred()) {
667 : 0 : goto exit;
668 : : }
669 [ # # ]: 0 : if (nargs < 2) {
670 : 0 : goto skip_optional;
671 : : }
672 : 0 : y_obj = args[1];
673 : 0 : skip_optional:
674 : 0 : return_value = cmath_log_impl(module, x, y_obj);
675 : :
676 : 0 : exit:
677 : 0 : 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 *
693 : 0 : cmath_phase(PyObject *module, PyObject *arg)
694 : : {
695 : 0 : PyObject *return_value = NULL;
696 : : Py_complex z;
697 : :
698 : 0 : z = PyComplex_AsCComplex(arg);
699 [ # # ]: 0 : if (PyErr_Occurred()) {
700 : 0 : goto exit;
701 : : }
702 : 0 : return_value = cmath_phase_impl(module, z);
703 : :
704 : 0 : exit:
705 : 0 : 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 *
723 : 0 : cmath_polar(PyObject *module, PyObject *arg)
724 : : {
725 : 0 : PyObject *return_value = NULL;
726 : : Py_complex z;
727 : :
728 : 0 : z = PyComplex_AsCComplex(arg);
729 [ # # ]: 0 : if (PyErr_Occurred()) {
730 : 0 : goto exit;
731 : : }
732 : 0 : return_value = cmath_polar_impl(module, z);
733 : :
734 : 0 : exit:
735 : 0 : 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 *
751 : 0 : cmath_rect(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
752 : : {
753 : 0 : PyObject *return_value = NULL;
754 : : double r;
755 : : double phi;
756 : :
757 [ # # # # : 0 : if (!_PyArg_CheckPositional("rect", nargs, 2, 2)) {
# # ]
758 : 0 : goto exit;
759 : : }
760 [ # # ]: 0 : if (PyFloat_CheckExact(args[0])) {
761 : 0 : r = PyFloat_AS_DOUBLE(args[0]);
762 : : }
763 : : else
764 : : {
765 : 0 : r = PyFloat_AsDouble(args[0]);
766 [ # # # # ]: 0 : if (r == -1.0 && PyErr_Occurred()) {
767 : 0 : goto exit;
768 : : }
769 : : }
770 [ # # ]: 0 : if (PyFloat_CheckExact(args[1])) {
771 : 0 : phi = PyFloat_AS_DOUBLE(args[1]);
772 : : }
773 : : else
774 : : {
775 : 0 : phi = PyFloat_AsDouble(args[1]);
776 [ # # # # ]: 0 : if (phi == -1.0 && PyErr_Occurred()) {
777 : 0 : goto exit;
778 : : }
779 : : }
780 : 0 : return_value = cmath_rect_impl(module, r, phi);
781 : :
782 : 0 : exit:
783 : 0 : 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 *
799 : 0 : cmath_isfinite(PyObject *module, PyObject *arg)
800 : : {
801 : 0 : PyObject *return_value = NULL;
802 : : Py_complex z;
803 : :
804 : 0 : z = PyComplex_AsCComplex(arg);
805 [ # # ]: 0 : if (PyErr_Occurred()) {
806 : 0 : goto exit;
807 : : }
808 : 0 : return_value = cmath_isfinite_impl(module, z);
809 : :
810 : 0 : exit:
811 : 0 : 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 *
827 : 0 : cmath_isnan(PyObject *module, PyObject *arg)
828 : : {
829 : 0 : PyObject *return_value = NULL;
830 : : Py_complex z;
831 : :
832 : 0 : z = PyComplex_AsCComplex(arg);
833 [ # # ]: 0 : if (PyErr_Occurred()) {
834 : 0 : goto exit;
835 : : }
836 : 0 : return_value = cmath_isnan_impl(module, z);
837 : :
838 : 0 : exit:
839 : 0 : 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 *
855 : 0 : cmath_isinf(PyObject *module, PyObject *arg)
856 : : {
857 : 0 : PyObject *return_value = NULL;
858 : : Py_complex z;
859 : :
860 : 0 : z = PyComplex_AsCComplex(arg);
861 [ # # ]: 0 : if (PyErr_Occurred()) {
862 : 0 : goto exit;
863 : : }
864 : 0 : return_value = cmath_isinf_impl(module, z);
865 : :
866 : 0 : exit:
867 : 0 : 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 *
899 : 0 : cmath_isclose(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
900 : : {
901 : 0 : 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_ID(a), &_Py_ID(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 [ # # ]: 0 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
929 : : Py_complex a;
930 : : Py_complex b;
931 : 0 : double rel_tol = 1e-09;
932 : 0 : double abs_tol = 0.0;
933 : : int _return_value;
934 : :
935 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
# # # # ]
936 [ # # ]: 0 : if (!args) {
937 : 0 : goto exit;
938 : : }
939 : 0 : a = PyComplex_AsCComplex(args[0]);
940 [ # # ]: 0 : if (PyErr_Occurred()) {
941 : 0 : goto exit;
942 : : }
943 : 0 : b = PyComplex_AsCComplex(args[1]);
944 [ # # ]: 0 : if (PyErr_Occurred()) {
945 : 0 : goto exit;
946 : : }
947 [ # # ]: 0 : if (!noptargs) {
948 : 0 : goto skip_optional_kwonly;
949 : : }
950 [ # # ]: 0 : if (args[2]) {
951 [ # # ]: 0 : if (PyFloat_CheckExact(args[2])) {
952 : 0 : rel_tol = PyFloat_AS_DOUBLE(args[2]);
953 : : }
954 : : else
955 : : {
956 : 0 : rel_tol = PyFloat_AsDouble(args[2]);
957 [ # # # # ]: 0 : if (rel_tol == -1.0 && PyErr_Occurred()) {
958 : 0 : goto exit;
959 : : }
960 : : }
961 [ # # ]: 0 : if (!--noptargs) {
962 : 0 : goto skip_optional_kwonly;
963 : : }
964 : : }
965 [ # # ]: 0 : if (PyFloat_CheckExact(args[3])) {
966 : 0 : abs_tol = PyFloat_AS_DOUBLE(args[3]);
967 : : }
968 : : else
969 : : {
970 : 0 : abs_tol = PyFloat_AsDouble(args[3]);
971 [ # # # # ]: 0 : if (abs_tol == -1.0 && PyErr_Occurred()) {
972 : 0 : goto exit;
973 : : }
974 : : }
975 : 0 : skip_optional_kwonly:
976 : 0 : _return_value = cmath_isclose_impl(module, a, b, rel_tol, abs_tol);
977 [ # # # # ]: 0 : if ((_return_value == -1) && PyErr_Occurred()) {
978 : 0 : goto exit;
979 : : }
980 : 0 : return_value = PyBool_FromLong((long)_return_value);
981 : :
982 : 0 : exit:
983 : 0 : return return_value;
984 : : }
985 : : /*[clinic end generated code: output=87f609786ef270cd input=a9049054013a1b77]*/
|