blob: a255353d4ae31124bf356ccbf585633dc17a6db2 [file] [log] [blame]
Brett Cannonb0fc4902014-10-14 17:37:02 -04001/*[clinic input]
2preserve
3[clinic start generated code]*/
4
5PyDoc_STRVAR(cmath_acos__doc__,
6"acos($module, z, /)\n"
7"--\n"
8"\n"
9"Return the arc cosine of z.");
10
11#define CMATH_ACOS_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +030012 {"acos", (PyCFunction)cmath_acos, METH_O, cmath_acos__doc__},
Brett Cannonb0fc4902014-10-14 17:37:02 -040013
14static Py_complex
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030015cmath_acos_impl(PyObject *module, Py_complex z);
Brett Cannonb0fc4902014-10-14 17:37:02 -040016
17static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030018cmath_acos(PyObject *module, PyObject *arg)
Brett Cannonb0fc4902014-10-14 17:37:02 -040019{
20 PyObject *return_value = NULL;
21 Py_complex z;
22 Py_complex _return_value;
23
Serhiy Storchaka247789c2015-04-24 00:40:51 +030024 if (!PyArg_Parse(arg, "D:acos", &z))
Brett Cannonb0fc4902014-10-14 17:37:02 -040025 goto exit;
26 /* modifications for z */
27 errno = 0; PyFPE_START_PROTECT("complex function", goto exit);
28 _return_value = cmath_acos_impl(module, z);
29 PyFPE_END_PROTECT(_return_value);
30 if (errno == EDOM) {
31 PyErr_SetString(PyExc_ValueError, "math domain error");
32 goto exit;
33 }
34 else if (errno == ERANGE) {
35 PyErr_SetString(PyExc_OverflowError, "math range error");
36 goto exit;
37 }
38 else {
39 return_value = PyComplex_FromCComplex(_return_value);
40 }
41
42exit:
43 return return_value;
44}
45
46PyDoc_STRVAR(cmath_acosh__doc__,
47"acosh($module, z, /)\n"
48"--\n"
49"\n"
Mark Dickinsoncc8617b2015-01-11 13:22:44 +000050"Return the inverse hyperbolic cosine of z.");
Brett Cannonb0fc4902014-10-14 17:37:02 -040051
52#define CMATH_ACOSH_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +030053 {"acosh", (PyCFunction)cmath_acosh, METH_O, cmath_acosh__doc__},
Brett Cannonb0fc4902014-10-14 17:37:02 -040054
55static Py_complex
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030056cmath_acosh_impl(PyObject *module, Py_complex z);
Brett Cannonb0fc4902014-10-14 17:37:02 -040057
58static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030059cmath_acosh(PyObject *module, PyObject *arg)
Brett Cannonb0fc4902014-10-14 17:37:02 -040060{
61 PyObject *return_value = NULL;
62 Py_complex z;
63 Py_complex _return_value;
64
Serhiy Storchaka247789c2015-04-24 00:40:51 +030065 if (!PyArg_Parse(arg, "D:acosh", &z))
Brett Cannonb0fc4902014-10-14 17:37:02 -040066 goto exit;
67 /* modifications for z */
68 errno = 0; PyFPE_START_PROTECT("complex function", goto exit);
69 _return_value = cmath_acosh_impl(module, z);
70 PyFPE_END_PROTECT(_return_value);
71 if (errno == EDOM) {
72 PyErr_SetString(PyExc_ValueError, "math domain error");
73 goto exit;
74 }
75 else if (errno == ERANGE) {
76 PyErr_SetString(PyExc_OverflowError, "math range error");
77 goto exit;
78 }
79 else {
80 return_value = PyComplex_FromCComplex(_return_value);
81 }
82
83exit:
84 return return_value;
85}
86
87PyDoc_STRVAR(cmath_asin__doc__,
88"asin($module, z, /)\n"
89"--\n"
90"\n"
91"Return the arc sine of z.");
92
93#define CMATH_ASIN_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +030094 {"asin", (PyCFunction)cmath_asin, METH_O, cmath_asin__doc__},
Brett Cannonb0fc4902014-10-14 17:37:02 -040095
96static Py_complex
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030097cmath_asin_impl(PyObject *module, Py_complex z);
Brett Cannonb0fc4902014-10-14 17:37:02 -040098
99static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300100cmath_asin(PyObject *module, PyObject *arg)
Brett Cannonb0fc4902014-10-14 17:37:02 -0400101{
102 PyObject *return_value = NULL;
103 Py_complex z;
104 Py_complex _return_value;
105
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300106 if (!PyArg_Parse(arg, "D:asin", &z))
Brett Cannonb0fc4902014-10-14 17:37:02 -0400107 goto exit;
108 /* modifications for z */
109 errno = 0; PyFPE_START_PROTECT("complex function", goto exit);
110 _return_value = cmath_asin_impl(module, z);
111 PyFPE_END_PROTECT(_return_value);
112 if (errno == EDOM) {
113 PyErr_SetString(PyExc_ValueError, "math domain error");
114 goto exit;
115 }
116 else if (errno == ERANGE) {
117 PyErr_SetString(PyExc_OverflowError, "math range error");
118 goto exit;
119 }
120 else {
121 return_value = PyComplex_FromCComplex(_return_value);
122 }
123
124exit:
125 return return_value;
126}
127
128PyDoc_STRVAR(cmath_asinh__doc__,
129"asinh($module, z, /)\n"
130"--\n"
131"\n"
Mark Dickinsoncc8617b2015-01-11 13:22:44 +0000132"Return the inverse hyperbolic sine of z.");
Brett Cannonb0fc4902014-10-14 17:37:02 -0400133
134#define CMATH_ASINH_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300135 {"asinh", (PyCFunction)cmath_asinh, METH_O, cmath_asinh__doc__},
Brett Cannonb0fc4902014-10-14 17:37:02 -0400136
137static Py_complex
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300138cmath_asinh_impl(PyObject *module, Py_complex z);
Brett Cannonb0fc4902014-10-14 17:37:02 -0400139
140static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300141cmath_asinh(PyObject *module, PyObject *arg)
Brett Cannonb0fc4902014-10-14 17:37:02 -0400142{
143 PyObject *return_value = NULL;
144 Py_complex z;
145 Py_complex _return_value;
146
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300147 if (!PyArg_Parse(arg, "D:asinh", &z))
Brett Cannonb0fc4902014-10-14 17:37:02 -0400148 goto exit;
149 /* modifications for z */
150 errno = 0; PyFPE_START_PROTECT("complex function", goto exit);
151 _return_value = cmath_asinh_impl(module, z);
152 PyFPE_END_PROTECT(_return_value);
153 if (errno == EDOM) {
154 PyErr_SetString(PyExc_ValueError, "math domain error");
155 goto exit;
156 }
157 else if (errno == ERANGE) {
158 PyErr_SetString(PyExc_OverflowError, "math range error");
159 goto exit;
160 }
161 else {
162 return_value = PyComplex_FromCComplex(_return_value);
163 }
164
165exit:
166 return return_value;
167}
168
169PyDoc_STRVAR(cmath_atan__doc__,
170"atan($module, z, /)\n"
171"--\n"
172"\n"
173"Return the arc tangent of z.");
174
175#define CMATH_ATAN_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300176 {"atan", (PyCFunction)cmath_atan, METH_O, cmath_atan__doc__},
Brett Cannonb0fc4902014-10-14 17:37:02 -0400177
178static Py_complex
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300179cmath_atan_impl(PyObject *module, Py_complex z);
Brett Cannonb0fc4902014-10-14 17:37:02 -0400180
181static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300182cmath_atan(PyObject *module, PyObject *arg)
Brett Cannonb0fc4902014-10-14 17:37:02 -0400183{
184 PyObject *return_value = NULL;
185 Py_complex z;
186 Py_complex _return_value;
187
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300188 if (!PyArg_Parse(arg, "D:atan", &z))
Brett Cannonb0fc4902014-10-14 17:37:02 -0400189 goto exit;
190 /* modifications for z */
191 errno = 0; PyFPE_START_PROTECT("complex function", goto exit);
192 _return_value = cmath_atan_impl(module, z);
193 PyFPE_END_PROTECT(_return_value);
194 if (errno == EDOM) {
195 PyErr_SetString(PyExc_ValueError, "math domain error");
196 goto exit;
197 }
198 else if (errno == ERANGE) {
199 PyErr_SetString(PyExc_OverflowError, "math range error");
200 goto exit;
201 }
202 else {
203 return_value = PyComplex_FromCComplex(_return_value);
204 }
205
206exit:
207 return return_value;
208}
209
210PyDoc_STRVAR(cmath_atanh__doc__,
211"atanh($module, z, /)\n"
212"--\n"
213"\n"
Mark Dickinsoncc8617b2015-01-11 13:22:44 +0000214"Return the inverse hyperbolic tangent of z.");
Brett Cannonb0fc4902014-10-14 17:37:02 -0400215
216#define CMATH_ATANH_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300217 {"atanh", (PyCFunction)cmath_atanh, METH_O, cmath_atanh__doc__},
Brett Cannonb0fc4902014-10-14 17:37:02 -0400218
219static Py_complex
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300220cmath_atanh_impl(PyObject *module, Py_complex z);
Brett Cannonb0fc4902014-10-14 17:37:02 -0400221
222static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300223cmath_atanh(PyObject *module, PyObject *arg)
Brett Cannonb0fc4902014-10-14 17:37:02 -0400224{
225 PyObject *return_value = NULL;
226 Py_complex z;
227 Py_complex _return_value;
228
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300229 if (!PyArg_Parse(arg, "D:atanh", &z))
Brett Cannonb0fc4902014-10-14 17:37:02 -0400230 goto exit;
231 /* modifications for z */
232 errno = 0; PyFPE_START_PROTECT("complex function", goto exit);
233 _return_value = cmath_atanh_impl(module, z);
234 PyFPE_END_PROTECT(_return_value);
235 if (errno == EDOM) {
236 PyErr_SetString(PyExc_ValueError, "math domain error");
237 goto exit;
238 }
239 else if (errno == ERANGE) {
240 PyErr_SetString(PyExc_OverflowError, "math range error");
241 goto exit;
242 }
243 else {
244 return_value = PyComplex_FromCComplex(_return_value);
245 }
246
247exit:
248 return return_value;
249}
250
251PyDoc_STRVAR(cmath_cos__doc__,
252"cos($module, z, /)\n"
253"--\n"
254"\n"
255"Return the cosine of z.");
256
257#define CMATH_COS_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300258 {"cos", (PyCFunction)cmath_cos, METH_O, cmath_cos__doc__},
Brett Cannonb0fc4902014-10-14 17:37:02 -0400259
260static Py_complex
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300261cmath_cos_impl(PyObject *module, Py_complex z);
Brett Cannonb0fc4902014-10-14 17:37:02 -0400262
263static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300264cmath_cos(PyObject *module, PyObject *arg)
Brett Cannonb0fc4902014-10-14 17:37:02 -0400265{
266 PyObject *return_value = NULL;
267 Py_complex z;
268 Py_complex _return_value;
269
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300270 if (!PyArg_Parse(arg, "D:cos", &z))
Brett Cannonb0fc4902014-10-14 17:37:02 -0400271 goto exit;
272 /* modifications for z */
273 errno = 0; PyFPE_START_PROTECT("complex function", goto exit);
274 _return_value = cmath_cos_impl(module, z);
275 PyFPE_END_PROTECT(_return_value);
276 if (errno == EDOM) {
277 PyErr_SetString(PyExc_ValueError, "math domain error");
278 goto exit;
279 }
280 else if (errno == ERANGE) {
281 PyErr_SetString(PyExc_OverflowError, "math range error");
282 goto exit;
283 }
284 else {
285 return_value = PyComplex_FromCComplex(_return_value);
286 }
287
288exit:
289 return return_value;
290}
291
292PyDoc_STRVAR(cmath_cosh__doc__,
293"cosh($module, z, /)\n"
294"--\n"
295"\n"
296"Return the hyperbolic cosine of z.");
297
298#define CMATH_COSH_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300299 {"cosh", (PyCFunction)cmath_cosh, METH_O, cmath_cosh__doc__},
Brett Cannonb0fc4902014-10-14 17:37:02 -0400300
301static Py_complex
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300302cmath_cosh_impl(PyObject *module, Py_complex z);
Brett Cannonb0fc4902014-10-14 17:37:02 -0400303
304static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300305cmath_cosh(PyObject *module, PyObject *arg)
Brett Cannonb0fc4902014-10-14 17:37:02 -0400306{
307 PyObject *return_value = NULL;
308 Py_complex z;
309 Py_complex _return_value;
310
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300311 if (!PyArg_Parse(arg, "D:cosh", &z))
Brett Cannonb0fc4902014-10-14 17:37:02 -0400312 goto exit;
313 /* modifications for z */
314 errno = 0; PyFPE_START_PROTECT("complex function", goto exit);
315 _return_value = cmath_cosh_impl(module, z);
316 PyFPE_END_PROTECT(_return_value);
317 if (errno == EDOM) {
318 PyErr_SetString(PyExc_ValueError, "math domain error");
319 goto exit;
320 }
321 else if (errno == ERANGE) {
322 PyErr_SetString(PyExc_OverflowError, "math range error");
323 goto exit;
324 }
325 else {
326 return_value = PyComplex_FromCComplex(_return_value);
327 }
328
329exit:
330 return return_value;
331}
332
333PyDoc_STRVAR(cmath_exp__doc__,
334"exp($module, z, /)\n"
335"--\n"
336"\n"
337"Return the exponential value e**z.");
338
339#define CMATH_EXP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300340 {"exp", (PyCFunction)cmath_exp, METH_O, cmath_exp__doc__},
Brett Cannonb0fc4902014-10-14 17:37:02 -0400341
342static Py_complex
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300343cmath_exp_impl(PyObject *module, Py_complex z);
Brett Cannonb0fc4902014-10-14 17:37:02 -0400344
345static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300346cmath_exp(PyObject *module, PyObject *arg)
Brett Cannonb0fc4902014-10-14 17:37:02 -0400347{
348 PyObject *return_value = NULL;
349 Py_complex z;
350 Py_complex _return_value;
351
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300352 if (!PyArg_Parse(arg, "D:exp", &z))
Brett Cannonb0fc4902014-10-14 17:37:02 -0400353 goto exit;
354 /* modifications for z */
355 errno = 0; PyFPE_START_PROTECT("complex function", goto exit);
356 _return_value = cmath_exp_impl(module, z);
357 PyFPE_END_PROTECT(_return_value);
358 if (errno == EDOM) {
359 PyErr_SetString(PyExc_ValueError, "math domain error");
360 goto exit;
361 }
362 else if (errno == ERANGE) {
363 PyErr_SetString(PyExc_OverflowError, "math range error");
364 goto exit;
365 }
366 else {
367 return_value = PyComplex_FromCComplex(_return_value);
368 }
369
370exit:
371 return return_value;
372}
373
374PyDoc_STRVAR(cmath_log10__doc__,
375"log10($module, z, /)\n"
376"--\n"
377"\n"
378"Return the base-10 logarithm of z.");
379
380#define CMATH_LOG10_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300381 {"log10", (PyCFunction)cmath_log10, METH_O, cmath_log10__doc__},
Brett Cannonb0fc4902014-10-14 17:37:02 -0400382
383static Py_complex
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300384cmath_log10_impl(PyObject *module, Py_complex z);
Brett Cannonb0fc4902014-10-14 17:37:02 -0400385
386static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300387cmath_log10(PyObject *module, PyObject *arg)
Brett Cannonb0fc4902014-10-14 17:37:02 -0400388{
389 PyObject *return_value = NULL;
390 Py_complex z;
391 Py_complex _return_value;
392
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300393 if (!PyArg_Parse(arg, "D:log10", &z))
Brett Cannonb0fc4902014-10-14 17:37:02 -0400394 goto exit;
395 /* modifications for z */
396 errno = 0; PyFPE_START_PROTECT("complex function", goto exit);
397 _return_value = cmath_log10_impl(module, z);
398 PyFPE_END_PROTECT(_return_value);
399 if (errno == EDOM) {
400 PyErr_SetString(PyExc_ValueError, "math domain error");
401 goto exit;
402 }
403 else if (errno == ERANGE) {
404 PyErr_SetString(PyExc_OverflowError, "math range error");
405 goto exit;
406 }
407 else {
408 return_value = PyComplex_FromCComplex(_return_value);
409 }
410
411exit:
412 return return_value;
413}
414
415PyDoc_STRVAR(cmath_sin__doc__,
416"sin($module, z, /)\n"
417"--\n"
418"\n"
419"Return the sine of z.");
420
421#define CMATH_SIN_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300422 {"sin", (PyCFunction)cmath_sin, METH_O, cmath_sin__doc__},
Brett Cannonb0fc4902014-10-14 17:37:02 -0400423
424static Py_complex
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300425cmath_sin_impl(PyObject *module, Py_complex z);
Brett Cannonb0fc4902014-10-14 17:37:02 -0400426
427static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300428cmath_sin(PyObject *module, PyObject *arg)
Brett Cannonb0fc4902014-10-14 17:37:02 -0400429{
430 PyObject *return_value = NULL;
431 Py_complex z;
432 Py_complex _return_value;
433
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300434 if (!PyArg_Parse(arg, "D:sin", &z))
Brett Cannonb0fc4902014-10-14 17:37:02 -0400435 goto exit;
436 /* modifications for z */
437 errno = 0; PyFPE_START_PROTECT("complex function", goto exit);
438 _return_value = cmath_sin_impl(module, z);
439 PyFPE_END_PROTECT(_return_value);
440 if (errno == EDOM) {
441 PyErr_SetString(PyExc_ValueError, "math domain error");
442 goto exit;
443 }
444 else if (errno == ERANGE) {
445 PyErr_SetString(PyExc_OverflowError, "math range error");
446 goto exit;
447 }
448 else {
449 return_value = PyComplex_FromCComplex(_return_value);
450 }
451
452exit:
453 return return_value;
454}
455
456PyDoc_STRVAR(cmath_sinh__doc__,
457"sinh($module, z, /)\n"
458"--\n"
459"\n"
460"Return the hyperbolic sine of z.");
461
462#define CMATH_SINH_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300463 {"sinh", (PyCFunction)cmath_sinh, METH_O, cmath_sinh__doc__},
Brett Cannonb0fc4902014-10-14 17:37:02 -0400464
465static Py_complex
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300466cmath_sinh_impl(PyObject *module, Py_complex z);
Brett Cannonb0fc4902014-10-14 17:37:02 -0400467
468static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300469cmath_sinh(PyObject *module, PyObject *arg)
Brett Cannonb0fc4902014-10-14 17:37:02 -0400470{
471 PyObject *return_value = NULL;
472 Py_complex z;
473 Py_complex _return_value;
474
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300475 if (!PyArg_Parse(arg, "D:sinh", &z))
Brett Cannonb0fc4902014-10-14 17:37:02 -0400476 goto exit;
477 /* modifications for z */
478 errno = 0; PyFPE_START_PROTECT("complex function", goto exit);
479 _return_value = cmath_sinh_impl(module, z);
480 PyFPE_END_PROTECT(_return_value);
481 if (errno == EDOM) {
482 PyErr_SetString(PyExc_ValueError, "math domain error");
483 goto exit;
484 }
485 else if (errno == ERANGE) {
486 PyErr_SetString(PyExc_OverflowError, "math range error");
487 goto exit;
488 }
489 else {
490 return_value = PyComplex_FromCComplex(_return_value);
491 }
492
493exit:
494 return return_value;
495}
496
497PyDoc_STRVAR(cmath_sqrt__doc__,
498"sqrt($module, z, /)\n"
499"--\n"
500"\n"
501"Return the square root of z.");
502
503#define CMATH_SQRT_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300504 {"sqrt", (PyCFunction)cmath_sqrt, METH_O, cmath_sqrt__doc__},
Brett Cannonb0fc4902014-10-14 17:37:02 -0400505
506static Py_complex
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300507cmath_sqrt_impl(PyObject *module, Py_complex z);
Brett Cannonb0fc4902014-10-14 17:37:02 -0400508
509static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300510cmath_sqrt(PyObject *module, PyObject *arg)
Brett Cannonb0fc4902014-10-14 17:37:02 -0400511{
512 PyObject *return_value = NULL;
513 Py_complex z;
514 Py_complex _return_value;
515
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300516 if (!PyArg_Parse(arg, "D:sqrt", &z))
Brett Cannonb0fc4902014-10-14 17:37:02 -0400517 goto exit;
518 /* modifications for z */
519 errno = 0; PyFPE_START_PROTECT("complex function", goto exit);
520 _return_value = cmath_sqrt_impl(module, z);
521 PyFPE_END_PROTECT(_return_value);
522 if (errno == EDOM) {
523 PyErr_SetString(PyExc_ValueError, "math domain error");
524 goto exit;
525 }
526 else if (errno == ERANGE) {
527 PyErr_SetString(PyExc_OverflowError, "math range error");
528 goto exit;
529 }
530 else {
531 return_value = PyComplex_FromCComplex(_return_value);
532 }
533
534exit:
535 return return_value;
536}
537
538PyDoc_STRVAR(cmath_tan__doc__,
539"tan($module, z, /)\n"
540"--\n"
541"\n"
542"Return the tangent of z.");
543
544#define CMATH_TAN_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300545 {"tan", (PyCFunction)cmath_tan, METH_O, cmath_tan__doc__},
Brett Cannonb0fc4902014-10-14 17:37:02 -0400546
547static Py_complex
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300548cmath_tan_impl(PyObject *module, Py_complex z);
Brett Cannonb0fc4902014-10-14 17:37:02 -0400549
550static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300551cmath_tan(PyObject *module, PyObject *arg)
Brett Cannonb0fc4902014-10-14 17:37:02 -0400552{
553 PyObject *return_value = NULL;
554 Py_complex z;
555 Py_complex _return_value;
556
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300557 if (!PyArg_Parse(arg, "D:tan", &z))
Brett Cannonb0fc4902014-10-14 17:37:02 -0400558 goto exit;
559 /* modifications for z */
560 errno = 0; PyFPE_START_PROTECT("complex function", goto exit);
561 _return_value = cmath_tan_impl(module, z);
562 PyFPE_END_PROTECT(_return_value);
563 if (errno == EDOM) {
564 PyErr_SetString(PyExc_ValueError, "math domain error");
565 goto exit;
566 }
567 else if (errno == ERANGE) {
568 PyErr_SetString(PyExc_OverflowError, "math range error");
569 goto exit;
570 }
571 else {
572 return_value = PyComplex_FromCComplex(_return_value);
573 }
574
575exit:
576 return return_value;
577}
578
579PyDoc_STRVAR(cmath_tanh__doc__,
580"tanh($module, z, /)\n"
581"--\n"
582"\n"
583"Return the hyperbolic tangent of z.");
584
585#define CMATH_TANH_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300586 {"tanh", (PyCFunction)cmath_tanh, METH_O, cmath_tanh__doc__},
Brett Cannonb0fc4902014-10-14 17:37:02 -0400587
588static Py_complex
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300589cmath_tanh_impl(PyObject *module, Py_complex z);
Brett Cannonb0fc4902014-10-14 17:37:02 -0400590
591static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300592cmath_tanh(PyObject *module, PyObject *arg)
Brett Cannonb0fc4902014-10-14 17:37:02 -0400593{
594 PyObject *return_value = NULL;
595 Py_complex z;
596 Py_complex _return_value;
597
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300598 if (!PyArg_Parse(arg, "D:tanh", &z))
Brett Cannonb0fc4902014-10-14 17:37:02 -0400599 goto exit;
600 /* modifications for z */
601 errno = 0; PyFPE_START_PROTECT("complex function", goto exit);
602 _return_value = cmath_tanh_impl(module, z);
603 PyFPE_END_PROTECT(_return_value);
604 if (errno == EDOM) {
605 PyErr_SetString(PyExc_ValueError, "math domain error");
606 goto exit;
607 }
608 else if (errno == ERANGE) {
609 PyErr_SetString(PyExc_OverflowError, "math range error");
610 goto exit;
611 }
612 else {
613 return_value = PyComplex_FromCComplex(_return_value);
614 }
615
616exit:
617 return return_value;
618}
619
620PyDoc_STRVAR(cmath_log__doc__,
621"log($module, x, y_obj=None, /)\n"
622"--\n"
623"\n"
624"The logarithm of z to the given base.\n"
625"\n"
626"If the base not specified, returns the natural logarithm (base e) of z.");
627
628#define CMATH_LOG_METHODDEF \
629 {"log", (PyCFunction)cmath_log, METH_VARARGS, cmath_log__doc__},
630
631static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300632cmath_log_impl(PyObject *module, Py_complex x, PyObject *y_obj);
Brett Cannonb0fc4902014-10-14 17:37:02 -0400633
634static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300635cmath_log(PyObject *module, PyObject *args)
Brett Cannonb0fc4902014-10-14 17:37:02 -0400636{
637 PyObject *return_value = NULL;
638 Py_complex x;
639 PyObject *y_obj = NULL;
640
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300641 if (!PyArg_ParseTuple(args, "D|O:log",
Brett Cannonb0fc4902014-10-14 17:37:02 -0400642 &x, &y_obj))
643 goto exit;
644 return_value = cmath_log_impl(module, x, y_obj);
645
646exit:
647 return return_value;
648}
649
650PyDoc_STRVAR(cmath_phase__doc__,
651"phase($module, z, /)\n"
652"--\n"
653"\n"
654"Return argument, also known as the phase angle, of a complex.");
655
656#define CMATH_PHASE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300657 {"phase", (PyCFunction)cmath_phase, METH_O, cmath_phase__doc__},
Brett Cannonb0fc4902014-10-14 17:37:02 -0400658
659static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300660cmath_phase_impl(PyObject *module, Py_complex z);
Brett Cannonb0fc4902014-10-14 17:37:02 -0400661
662static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300663cmath_phase(PyObject *module, PyObject *arg)
Brett Cannonb0fc4902014-10-14 17:37:02 -0400664{
665 PyObject *return_value = NULL;
666 Py_complex z;
667
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300668 if (!PyArg_Parse(arg, "D:phase", &z))
Brett Cannonb0fc4902014-10-14 17:37:02 -0400669 goto exit;
670 return_value = cmath_phase_impl(module, z);
671
672exit:
673 return return_value;
674}
675
676PyDoc_STRVAR(cmath_polar__doc__,
677"polar($module, z, /)\n"
678"--\n"
679"\n"
680"Convert a complex from rectangular coordinates to polar coordinates.\n"
681"\n"
682"r is the distance from 0 and phi the phase angle.");
683
684#define CMATH_POLAR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300685 {"polar", (PyCFunction)cmath_polar, METH_O, cmath_polar__doc__},
Brett Cannonb0fc4902014-10-14 17:37:02 -0400686
687static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300688cmath_polar_impl(PyObject *module, Py_complex z);
Brett Cannonb0fc4902014-10-14 17:37:02 -0400689
690static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300691cmath_polar(PyObject *module, PyObject *arg)
Brett Cannonb0fc4902014-10-14 17:37:02 -0400692{
693 PyObject *return_value = NULL;
694 Py_complex z;
695
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300696 if (!PyArg_Parse(arg, "D:polar", &z))
Brett Cannonb0fc4902014-10-14 17:37:02 -0400697 goto exit;
698 return_value = cmath_polar_impl(module, z);
699
700exit:
701 return return_value;
702}
703
704PyDoc_STRVAR(cmath_rect__doc__,
705"rect($module, r, phi, /)\n"
706"--\n"
707"\n"
708"Convert from polar coordinates to rectangular coordinates.");
709
710#define CMATH_RECT_METHODDEF \
711 {"rect", (PyCFunction)cmath_rect, METH_VARARGS, cmath_rect__doc__},
712
713static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300714cmath_rect_impl(PyObject *module, double r, double phi);
Brett Cannonb0fc4902014-10-14 17:37:02 -0400715
716static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300717cmath_rect(PyObject *module, PyObject *args)
Brett Cannonb0fc4902014-10-14 17:37:02 -0400718{
719 PyObject *return_value = NULL;
720 double r;
721 double phi;
722
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300723 if (!PyArg_ParseTuple(args, "dd:rect",
Brett Cannonb0fc4902014-10-14 17:37:02 -0400724 &r, &phi))
725 goto exit;
726 return_value = cmath_rect_impl(module, r, phi);
727
728exit:
729 return return_value;
730}
731
732PyDoc_STRVAR(cmath_isfinite__doc__,
733"isfinite($module, z, /)\n"
734"--\n"
735"\n"
736"Return True if both the real and imaginary parts of z are finite, else False.");
737
738#define CMATH_ISFINITE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300739 {"isfinite", (PyCFunction)cmath_isfinite, METH_O, cmath_isfinite__doc__},
Brett Cannonb0fc4902014-10-14 17:37:02 -0400740
741static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300742cmath_isfinite_impl(PyObject *module, Py_complex z);
Brett Cannonb0fc4902014-10-14 17:37:02 -0400743
744static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300745cmath_isfinite(PyObject *module, PyObject *arg)
Brett Cannonb0fc4902014-10-14 17:37:02 -0400746{
747 PyObject *return_value = NULL;
748 Py_complex z;
749
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300750 if (!PyArg_Parse(arg, "D:isfinite", &z))
Brett Cannonb0fc4902014-10-14 17:37:02 -0400751 goto exit;
752 return_value = cmath_isfinite_impl(module, z);
753
754exit:
755 return return_value;
756}
757
758PyDoc_STRVAR(cmath_isnan__doc__,
759"isnan($module, z, /)\n"
760"--\n"
761"\n"
762"Checks if the real or imaginary part of z not a number (NaN).");
763
764#define CMATH_ISNAN_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300765 {"isnan", (PyCFunction)cmath_isnan, METH_O, cmath_isnan__doc__},
Brett Cannonb0fc4902014-10-14 17:37:02 -0400766
767static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300768cmath_isnan_impl(PyObject *module, Py_complex z);
Brett Cannonb0fc4902014-10-14 17:37:02 -0400769
770static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300771cmath_isnan(PyObject *module, PyObject *arg)
Brett Cannonb0fc4902014-10-14 17:37:02 -0400772{
773 PyObject *return_value = NULL;
774 Py_complex z;
775
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300776 if (!PyArg_Parse(arg, "D:isnan", &z))
Brett Cannonb0fc4902014-10-14 17:37:02 -0400777 goto exit;
778 return_value = cmath_isnan_impl(module, z);
779
780exit:
781 return return_value;
782}
783
784PyDoc_STRVAR(cmath_isinf__doc__,
785"isinf($module, z, /)\n"
786"--\n"
787"\n"
788"Checks if the real or imaginary part of z is infinite.");
789
790#define CMATH_ISINF_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300791 {"isinf", (PyCFunction)cmath_isinf, METH_O, cmath_isinf__doc__},
Brett Cannonb0fc4902014-10-14 17:37:02 -0400792
793static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300794cmath_isinf_impl(PyObject *module, Py_complex z);
Brett Cannonb0fc4902014-10-14 17:37:02 -0400795
796static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300797cmath_isinf(PyObject *module, PyObject *arg)
Brett Cannonb0fc4902014-10-14 17:37:02 -0400798{
799 PyObject *return_value = NULL;
800 Py_complex z;
801
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300802 if (!PyArg_Parse(arg, "D:isinf", &z))
Brett Cannonb0fc4902014-10-14 17:37:02 -0400803 goto exit;
804 return_value = cmath_isinf_impl(module, z);
805
806exit:
807 return return_value;
808}
Tal Einatd5519ed2015-05-31 22:05:00 +0300809
810PyDoc_STRVAR(cmath_isclose__doc__,
811"isclose($module, /, a, b, *, rel_tol=1e-09, abs_tol=0.0)\n"
812"--\n"
813"\n"
814"Determine whether two complex numbers are close in value.\n"
815"\n"
816" rel_tol\n"
817" maximum difference for being considered \"close\", relative to the\n"
818" magnitude of the input values\n"
819" abs_tol\n"
820" maximum difference for being considered \"close\", regardless of the\n"
821" magnitude of the input values\n"
822"\n"
823"Return True if a is close in value to b, and False otherwise.\n"
824"\n"
825"For the values to be considered close, the difference between them must be\n"
826"smaller than at least one of the tolerances.\n"
827"\n"
828"-inf, inf and NaN behave similarly to the IEEE 754 Standard. That is, NaN is\n"
829"not close to anything, even itself. inf and -inf are only close to themselves.");
830
831#define CMATH_ISCLOSE_METHODDEF \
832 {"isclose", (PyCFunction)cmath_isclose, METH_VARARGS|METH_KEYWORDS, cmath_isclose__doc__},
833
834static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300835cmath_isclose_impl(PyObject *module, Py_complex a, Py_complex b,
Tal Einatd5519ed2015-05-31 22:05:00 +0300836 double rel_tol, double abs_tol);
837
838static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300839cmath_isclose(PyObject *module, PyObject *args, PyObject *kwargs)
Tal Einatd5519ed2015-05-31 22:05:00 +0300840{
841 PyObject *return_value = NULL;
842 static char *_keywords[] = {"a", "b", "rel_tol", "abs_tol", NULL};
843 Py_complex a;
844 Py_complex b;
845 double rel_tol = 1e-09;
846 double abs_tol = 0.0;
847 int _return_value;
848
849 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "DD|$dd:isclose", _keywords,
850 &a, &b, &rel_tol, &abs_tol))
851 goto exit;
852 _return_value = cmath_isclose_impl(module, a, b, rel_tol, abs_tol);
853 if ((_return_value == -1) && PyErr_Occurred())
854 goto exit;
855 return_value = PyBool_FromLong((long)_return_value);
856
857exit:
858 return return_value;
859}
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300860/*[clinic end generated code: output=732194029b7fb1e7 input=a9049054013a1b77]*/