blob: e46c31420e12fc809b6cf0d1ef07ddd15b012174 [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 Storchaka5dee6552016-06-09 16:16:06 +030024 if (!PyArg_Parse(arg, "D:acos", &z)) {
Brett Cannonb0fc4902014-10-14 17:37:02 -040025 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030026 }
Brett Cannonb0fc4902014-10-14 17:37:02 -040027 /* modifications for z */
28 errno = 0; PyFPE_START_PROTECT("complex function", goto exit);
29 _return_value = cmath_acos_impl(module, z);
30 PyFPE_END_PROTECT(_return_value);
31 if (errno == EDOM) {
32 PyErr_SetString(PyExc_ValueError, "math domain error");
33 goto exit;
34 }
35 else if (errno == ERANGE) {
36 PyErr_SetString(PyExc_OverflowError, "math range error");
37 goto exit;
38 }
39 else {
40 return_value = PyComplex_FromCComplex(_return_value);
41 }
42
43exit:
44 return return_value;
45}
46
47PyDoc_STRVAR(cmath_acosh__doc__,
48"acosh($module, z, /)\n"
49"--\n"
50"\n"
Mark Dickinsoncc8617b2015-01-11 13:22:44 +000051"Return the inverse hyperbolic cosine of z.");
Brett Cannonb0fc4902014-10-14 17:37:02 -040052
53#define CMATH_ACOSH_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +030054 {"acosh", (PyCFunction)cmath_acosh, METH_O, cmath_acosh__doc__},
Brett Cannonb0fc4902014-10-14 17:37:02 -040055
56static Py_complex
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030057cmath_acosh_impl(PyObject *module, Py_complex z);
Brett Cannonb0fc4902014-10-14 17:37:02 -040058
59static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030060cmath_acosh(PyObject *module, PyObject *arg)
Brett Cannonb0fc4902014-10-14 17:37:02 -040061{
62 PyObject *return_value = NULL;
63 Py_complex z;
64 Py_complex _return_value;
65
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030066 if (!PyArg_Parse(arg, "D:acosh", &z)) {
Brett Cannonb0fc4902014-10-14 17:37:02 -040067 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030068 }
Brett Cannonb0fc4902014-10-14 17:37:02 -040069 /* modifications for z */
70 errno = 0; PyFPE_START_PROTECT("complex function", goto exit);
71 _return_value = cmath_acosh_impl(module, z);
72 PyFPE_END_PROTECT(_return_value);
73 if (errno == EDOM) {
74 PyErr_SetString(PyExc_ValueError, "math domain error");
75 goto exit;
76 }
77 else if (errno == ERANGE) {
78 PyErr_SetString(PyExc_OverflowError, "math range error");
79 goto exit;
80 }
81 else {
82 return_value = PyComplex_FromCComplex(_return_value);
83 }
84
85exit:
86 return return_value;
87}
88
89PyDoc_STRVAR(cmath_asin__doc__,
90"asin($module, z, /)\n"
91"--\n"
92"\n"
93"Return the arc sine of z.");
94
95#define CMATH_ASIN_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +030096 {"asin", (PyCFunction)cmath_asin, METH_O, cmath_asin__doc__},
Brett Cannonb0fc4902014-10-14 17:37:02 -040097
98static Py_complex
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030099cmath_asin_impl(PyObject *module, Py_complex z);
Brett Cannonb0fc4902014-10-14 17:37:02 -0400100
101static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300102cmath_asin(PyObject *module, PyObject *arg)
Brett Cannonb0fc4902014-10-14 17:37:02 -0400103{
104 PyObject *return_value = NULL;
105 Py_complex z;
106 Py_complex _return_value;
107
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300108 if (!PyArg_Parse(arg, "D:asin", &z)) {
Brett Cannonb0fc4902014-10-14 17:37:02 -0400109 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300110 }
Brett Cannonb0fc4902014-10-14 17:37:02 -0400111 /* modifications for z */
112 errno = 0; PyFPE_START_PROTECT("complex function", goto exit);
113 _return_value = cmath_asin_impl(module, z);
114 PyFPE_END_PROTECT(_return_value);
115 if (errno == EDOM) {
116 PyErr_SetString(PyExc_ValueError, "math domain error");
117 goto exit;
118 }
119 else if (errno == ERANGE) {
120 PyErr_SetString(PyExc_OverflowError, "math range error");
121 goto exit;
122 }
123 else {
124 return_value = PyComplex_FromCComplex(_return_value);
125 }
126
127exit:
128 return return_value;
129}
130
131PyDoc_STRVAR(cmath_asinh__doc__,
132"asinh($module, z, /)\n"
133"--\n"
134"\n"
Mark Dickinsoncc8617b2015-01-11 13:22:44 +0000135"Return the inverse hyperbolic sine of z.");
Brett Cannonb0fc4902014-10-14 17:37:02 -0400136
137#define CMATH_ASINH_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300138 {"asinh", (PyCFunction)cmath_asinh, METH_O, cmath_asinh__doc__},
Brett Cannonb0fc4902014-10-14 17:37:02 -0400139
140static Py_complex
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300141cmath_asinh_impl(PyObject *module, Py_complex z);
Brett Cannonb0fc4902014-10-14 17:37:02 -0400142
143static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300144cmath_asinh(PyObject *module, PyObject *arg)
Brett Cannonb0fc4902014-10-14 17:37:02 -0400145{
146 PyObject *return_value = NULL;
147 Py_complex z;
148 Py_complex _return_value;
149
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300150 if (!PyArg_Parse(arg, "D:asinh", &z)) {
Brett Cannonb0fc4902014-10-14 17:37:02 -0400151 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300152 }
Brett Cannonb0fc4902014-10-14 17:37:02 -0400153 /* modifications for z */
154 errno = 0; PyFPE_START_PROTECT("complex function", goto exit);
155 _return_value = cmath_asinh_impl(module, z);
156 PyFPE_END_PROTECT(_return_value);
157 if (errno == EDOM) {
158 PyErr_SetString(PyExc_ValueError, "math domain error");
159 goto exit;
160 }
161 else if (errno == ERANGE) {
162 PyErr_SetString(PyExc_OverflowError, "math range error");
163 goto exit;
164 }
165 else {
166 return_value = PyComplex_FromCComplex(_return_value);
167 }
168
169exit:
170 return return_value;
171}
172
173PyDoc_STRVAR(cmath_atan__doc__,
174"atan($module, z, /)\n"
175"--\n"
176"\n"
177"Return the arc tangent of z.");
178
179#define CMATH_ATAN_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300180 {"atan", (PyCFunction)cmath_atan, METH_O, cmath_atan__doc__},
Brett Cannonb0fc4902014-10-14 17:37:02 -0400181
182static Py_complex
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300183cmath_atan_impl(PyObject *module, Py_complex z);
Brett Cannonb0fc4902014-10-14 17:37:02 -0400184
185static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300186cmath_atan(PyObject *module, PyObject *arg)
Brett Cannonb0fc4902014-10-14 17:37:02 -0400187{
188 PyObject *return_value = NULL;
189 Py_complex z;
190 Py_complex _return_value;
191
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300192 if (!PyArg_Parse(arg, "D:atan", &z)) {
Brett Cannonb0fc4902014-10-14 17:37:02 -0400193 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300194 }
Brett Cannonb0fc4902014-10-14 17:37:02 -0400195 /* modifications for z */
196 errno = 0; PyFPE_START_PROTECT("complex function", goto exit);
197 _return_value = cmath_atan_impl(module, z);
198 PyFPE_END_PROTECT(_return_value);
199 if (errno == EDOM) {
200 PyErr_SetString(PyExc_ValueError, "math domain error");
201 goto exit;
202 }
203 else if (errno == ERANGE) {
204 PyErr_SetString(PyExc_OverflowError, "math range error");
205 goto exit;
206 }
207 else {
208 return_value = PyComplex_FromCComplex(_return_value);
209 }
210
211exit:
212 return return_value;
213}
214
215PyDoc_STRVAR(cmath_atanh__doc__,
216"atanh($module, z, /)\n"
217"--\n"
218"\n"
Mark Dickinsoncc8617b2015-01-11 13:22:44 +0000219"Return the inverse hyperbolic tangent of z.");
Brett Cannonb0fc4902014-10-14 17:37:02 -0400220
221#define CMATH_ATANH_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300222 {"atanh", (PyCFunction)cmath_atanh, METH_O, cmath_atanh__doc__},
Brett Cannonb0fc4902014-10-14 17:37:02 -0400223
224static Py_complex
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300225cmath_atanh_impl(PyObject *module, Py_complex z);
Brett Cannonb0fc4902014-10-14 17:37:02 -0400226
227static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300228cmath_atanh(PyObject *module, PyObject *arg)
Brett Cannonb0fc4902014-10-14 17:37:02 -0400229{
230 PyObject *return_value = NULL;
231 Py_complex z;
232 Py_complex _return_value;
233
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300234 if (!PyArg_Parse(arg, "D:atanh", &z)) {
Brett Cannonb0fc4902014-10-14 17:37:02 -0400235 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300236 }
Brett Cannonb0fc4902014-10-14 17:37:02 -0400237 /* modifications for z */
238 errno = 0; PyFPE_START_PROTECT("complex function", goto exit);
239 _return_value = cmath_atanh_impl(module, z);
240 PyFPE_END_PROTECT(_return_value);
241 if (errno == EDOM) {
242 PyErr_SetString(PyExc_ValueError, "math domain error");
243 goto exit;
244 }
245 else if (errno == ERANGE) {
246 PyErr_SetString(PyExc_OverflowError, "math range error");
247 goto exit;
248 }
249 else {
250 return_value = PyComplex_FromCComplex(_return_value);
251 }
252
253exit:
254 return return_value;
255}
256
257PyDoc_STRVAR(cmath_cos__doc__,
258"cos($module, z, /)\n"
259"--\n"
260"\n"
261"Return the cosine of z.");
262
263#define CMATH_COS_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300264 {"cos", (PyCFunction)cmath_cos, METH_O, cmath_cos__doc__},
Brett Cannonb0fc4902014-10-14 17:37:02 -0400265
266static Py_complex
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300267cmath_cos_impl(PyObject *module, Py_complex z);
Brett Cannonb0fc4902014-10-14 17:37:02 -0400268
269static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300270cmath_cos(PyObject *module, PyObject *arg)
Brett Cannonb0fc4902014-10-14 17:37:02 -0400271{
272 PyObject *return_value = NULL;
273 Py_complex z;
274 Py_complex _return_value;
275
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300276 if (!PyArg_Parse(arg, "D:cos", &z)) {
Brett Cannonb0fc4902014-10-14 17:37:02 -0400277 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300278 }
Brett Cannonb0fc4902014-10-14 17:37:02 -0400279 /* modifications for z */
280 errno = 0; PyFPE_START_PROTECT("complex function", goto exit);
281 _return_value = cmath_cos_impl(module, z);
282 PyFPE_END_PROTECT(_return_value);
283 if (errno == EDOM) {
284 PyErr_SetString(PyExc_ValueError, "math domain error");
285 goto exit;
286 }
287 else if (errno == ERANGE) {
288 PyErr_SetString(PyExc_OverflowError, "math range error");
289 goto exit;
290 }
291 else {
292 return_value = PyComplex_FromCComplex(_return_value);
293 }
294
295exit:
296 return return_value;
297}
298
299PyDoc_STRVAR(cmath_cosh__doc__,
300"cosh($module, z, /)\n"
301"--\n"
302"\n"
303"Return the hyperbolic cosine of z.");
304
305#define CMATH_COSH_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300306 {"cosh", (PyCFunction)cmath_cosh, METH_O, cmath_cosh__doc__},
Brett Cannonb0fc4902014-10-14 17:37:02 -0400307
308static Py_complex
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300309cmath_cosh_impl(PyObject *module, Py_complex z);
Brett Cannonb0fc4902014-10-14 17:37:02 -0400310
311static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300312cmath_cosh(PyObject *module, PyObject *arg)
Brett Cannonb0fc4902014-10-14 17:37:02 -0400313{
314 PyObject *return_value = NULL;
315 Py_complex z;
316 Py_complex _return_value;
317
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300318 if (!PyArg_Parse(arg, "D:cosh", &z)) {
Brett Cannonb0fc4902014-10-14 17:37:02 -0400319 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300320 }
Brett Cannonb0fc4902014-10-14 17:37:02 -0400321 /* modifications for z */
322 errno = 0; PyFPE_START_PROTECT("complex function", goto exit);
323 _return_value = cmath_cosh_impl(module, z);
324 PyFPE_END_PROTECT(_return_value);
325 if (errno == EDOM) {
326 PyErr_SetString(PyExc_ValueError, "math domain error");
327 goto exit;
328 }
329 else if (errno == ERANGE) {
330 PyErr_SetString(PyExc_OverflowError, "math range error");
331 goto exit;
332 }
333 else {
334 return_value = PyComplex_FromCComplex(_return_value);
335 }
336
337exit:
338 return return_value;
339}
340
341PyDoc_STRVAR(cmath_exp__doc__,
342"exp($module, z, /)\n"
343"--\n"
344"\n"
345"Return the exponential value e**z.");
346
347#define CMATH_EXP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300348 {"exp", (PyCFunction)cmath_exp, METH_O, cmath_exp__doc__},
Brett Cannonb0fc4902014-10-14 17:37:02 -0400349
350static Py_complex
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300351cmath_exp_impl(PyObject *module, Py_complex z);
Brett Cannonb0fc4902014-10-14 17:37:02 -0400352
353static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300354cmath_exp(PyObject *module, PyObject *arg)
Brett Cannonb0fc4902014-10-14 17:37:02 -0400355{
356 PyObject *return_value = NULL;
357 Py_complex z;
358 Py_complex _return_value;
359
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300360 if (!PyArg_Parse(arg, "D:exp", &z)) {
Brett Cannonb0fc4902014-10-14 17:37:02 -0400361 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300362 }
Brett Cannonb0fc4902014-10-14 17:37:02 -0400363 /* modifications for z */
364 errno = 0; PyFPE_START_PROTECT("complex function", goto exit);
365 _return_value = cmath_exp_impl(module, z);
366 PyFPE_END_PROTECT(_return_value);
367 if (errno == EDOM) {
368 PyErr_SetString(PyExc_ValueError, "math domain error");
369 goto exit;
370 }
371 else if (errno == ERANGE) {
372 PyErr_SetString(PyExc_OverflowError, "math range error");
373 goto exit;
374 }
375 else {
376 return_value = PyComplex_FromCComplex(_return_value);
377 }
378
379exit:
380 return return_value;
381}
382
383PyDoc_STRVAR(cmath_log10__doc__,
384"log10($module, z, /)\n"
385"--\n"
386"\n"
387"Return the base-10 logarithm of z.");
388
389#define CMATH_LOG10_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300390 {"log10", (PyCFunction)cmath_log10, METH_O, cmath_log10__doc__},
Brett Cannonb0fc4902014-10-14 17:37:02 -0400391
392static Py_complex
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300393cmath_log10_impl(PyObject *module, Py_complex z);
Brett Cannonb0fc4902014-10-14 17:37:02 -0400394
395static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300396cmath_log10(PyObject *module, PyObject *arg)
Brett Cannonb0fc4902014-10-14 17:37:02 -0400397{
398 PyObject *return_value = NULL;
399 Py_complex z;
400 Py_complex _return_value;
401
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300402 if (!PyArg_Parse(arg, "D:log10", &z)) {
Brett Cannonb0fc4902014-10-14 17:37:02 -0400403 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300404 }
Brett Cannonb0fc4902014-10-14 17:37:02 -0400405 /* modifications for z */
406 errno = 0; PyFPE_START_PROTECT("complex function", goto exit);
407 _return_value = cmath_log10_impl(module, z);
408 PyFPE_END_PROTECT(_return_value);
409 if (errno == EDOM) {
410 PyErr_SetString(PyExc_ValueError, "math domain error");
411 goto exit;
412 }
413 else if (errno == ERANGE) {
414 PyErr_SetString(PyExc_OverflowError, "math range error");
415 goto exit;
416 }
417 else {
418 return_value = PyComplex_FromCComplex(_return_value);
419 }
420
421exit:
422 return return_value;
423}
424
425PyDoc_STRVAR(cmath_sin__doc__,
426"sin($module, z, /)\n"
427"--\n"
428"\n"
429"Return the sine of z.");
430
431#define CMATH_SIN_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300432 {"sin", (PyCFunction)cmath_sin, METH_O, cmath_sin__doc__},
Brett Cannonb0fc4902014-10-14 17:37:02 -0400433
434static Py_complex
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300435cmath_sin_impl(PyObject *module, Py_complex z);
Brett Cannonb0fc4902014-10-14 17:37:02 -0400436
437static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300438cmath_sin(PyObject *module, PyObject *arg)
Brett Cannonb0fc4902014-10-14 17:37:02 -0400439{
440 PyObject *return_value = NULL;
441 Py_complex z;
442 Py_complex _return_value;
443
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300444 if (!PyArg_Parse(arg, "D:sin", &z)) {
Brett Cannonb0fc4902014-10-14 17:37:02 -0400445 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300446 }
Brett Cannonb0fc4902014-10-14 17:37:02 -0400447 /* modifications for z */
448 errno = 0; PyFPE_START_PROTECT("complex function", goto exit);
449 _return_value = cmath_sin_impl(module, z);
450 PyFPE_END_PROTECT(_return_value);
451 if (errno == EDOM) {
452 PyErr_SetString(PyExc_ValueError, "math domain error");
453 goto exit;
454 }
455 else if (errno == ERANGE) {
456 PyErr_SetString(PyExc_OverflowError, "math range error");
457 goto exit;
458 }
459 else {
460 return_value = PyComplex_FromCComplex(_return_value);
461 }
462
463exit:
464 return return_value;
465}
466
467PyDoc_STRVAR(cmath_sinh__doc__,
468"sinh($module, z, /)\n"
469"--\n"
470"\n"
471"Return the hyperbolic sine of z.");
472
473#define CMATH_SINH_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300474 {"sinh", (PyCFunction)cmath_sinh, METH_O, cmath_sinh__doc__},
Brett Cannonb0fc4902014-10-14 17:37:02 -0400475
476static Py_complex
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300477cmath_sinh_impl(PyObject *module, Py_complex z);
Brett Cannonb0fc4902014-10-14 17:37:02 -0400478
479static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300480cmath_sinh(PyObject *module, PyObject *arg)
Brett Cannonb0fc4902014-10-14 17:37:02 -0400481{
482 PyObject *return_value = NULL;
483 Py_complex z;
484 Py_complex _return_value;
485
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300486 if (!PyArg_Parse(arg, "D:sinh", &z)) {
Brett Cannonb0fc4902014-10-14 17:37:02 -0400487 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300488 }
Brett Cannonb0fc4902014-10-14 17:37:02 -0400489 /* modifications for z */
490 errno = 0; PyFPE_START_PROTECT("complex function", goto exit);
491 _return_value = cmath_sinh_impl(module, z);
492 PyFPE_END_PROTECT(_return_value);
493 if (errno == EDOM) {
494 PyErr_SetString(PyExc_ValueError, "math domain error");
495 goto exit;
496 }
497 else if (errno == ERANGE) {
498 PyErr_SetString(PyExc_OverflowError, "math range error");
499 goto exit;
500 }
501 else {
502 return_value = PyComplex_FromCComplex(_return_value);
503 }
504
505exit:
506 return return_value;
507}
508
509PyDoc_STRVAR(cmath_sqrt__doc__,
510"sqrt($module, z, /)\n"
511"--\n"
512"\n"
513"Return the square root of z.");
514
515#define CMATH_SQRT_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300516 {"sqrt", (PyCFunction)cmath_sqrt, METH_O, cmath_sqrt__doc__},
Brett Cannonb0fc4902014-10-14 17:37:02 -0400517
518static Py_complex
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300519cmath_sqrt_impl(PyObject *module, Py_complex z);
Brett Cannonb0fc4902014-10-14 17:37:02 -0400520
521static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300522cmath_sqrt(PyObject *module, PyObject *arg)
Brett Cannonb0fc4902014-10-14 17:37:02 -0400523{
524 PyObject *return_value = NULL;
525 Py_complex z;
526 Py_complex _return_value;
527
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300528 if (!PyArg_Parse(arg, "D:sqrt", &z)) {
Brett Cannonb0fc4902014-10-14 17:37:02 -0400529 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300530 }
Brett Cannonb0fc4902014-10-14 17:37:02 -0400531 /* modifications for z */
532 errno = 0; PyFPE_START_PROTECT("complex function", goto exit);
533 _return_value = cmath_sqrt_impl(module, z);
534 PyFPE_END_PROTECT(_return_value);
535 if (errno == EDOM) {
536 PyErr_SetString(PyExc_ValueError, "math domain error");
537 goto exit;
538 }
539 else if (errno == ERANGE) {
540 PyErr_SetString(PyExc_OverflowError, "math range error");
541 goto exit;
542 }
543 else {
544 return_value = PyComplex_FromCComplex(_return_value);
545 }
546
547exit:
548 return return_value;
549}
550
551PyDoc_STRVAR(cmath_tan__doc__,
552"tan($module, z, /)\n"
553"--\n"
554"\n"
555"Return the tangent of z.");
556
557#define CMATH_TAN_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300558 {"tan", (PyCFunction)cmath_tan, METH_O, cmath_tan__doc__},
Brett Cannonb0fc4902014-10-14 17:37:02 -0400559
560static Py_complex
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300561cmath_tan_impl(PyObject *module, Py_complex z);
Brett Cannonb0fc4902014-10-14 17:37:02 -0400562
563static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300564cmath_tan(PyObject *module, PyObject *arg)
Brett Cannonb0fc4902014-10-14 17:37:02 -0400565{
566 PyObject *return_value = NULL;
567 Py_complex z;
568 Py_complex _return_value;
569
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300570 if (!PyArg_Parse(arg, "D:tan", &z)) {
Brett Cannonb0fc4902014-10-14 17:37:02 -0400571 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300572 }
Brett Cannonb0fc4902014-10-14 17:37:02 -0400573 /* modifications for z */
574 errno = 0; PyFPE_START_PROTECT("complex function", goto exit);
575 _return_value = cmath_tan_impl(module, z);
576 PyFPE_END_PROTECT(_return_value);
577 if (errno == EDOM) {
578 PyErr_SetString(PyExc_ValueError, "math domain error");
579 goto exit;
580 }
581 else if (errno == ERANGE) {
582 PyErr_SetString(PyExc_OverflowError, "math range error");
583 goto exit;
584 }
585 else {
586 return_value = PyComplex_FromCComplex(_return_value);
587 }
588
589exit:
590 return return_value;
591}
592
593PyDoc_STRVAR(cmath_tanh__doc__,
594"tanh($module, z, /)\n"
595"--\n"
596"\n"
597"Return the hyperbolic tangent of z.");
598
599#define CMATH_TANH_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300600 {"tanh", (PyCFunction)cmath_tanh, METH_O, cmath_tanh__doc__},
Brett Cannonb0fc4902014-10-14 17:37:02 -0400601
602static Py_complex
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300603cmath_tanh_impl(PyObject *module, Py_complex z);
Brett Cannonb0fc4902014-10-14 17:37:02 -0400604
605static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300606cmath_tanh(PyObject *module, PyObject *arg)
Brett Cannonb0fc4902014-10-14 17:37:02 -0400607{
608 PyObject *return_value = NULL;
609 Py_complex z;
610 Py_complex _return_value;
611
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300612 if (!PyArg_Parse(arg, "D:tanh", &z)) {
Brett Cannonb0fc4902014-10-14 17:37:02 -0400613 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300614 }
Brett Cannonb0fc4902014-10-14 17:37:02 -0400615 /* modifications for z */
616 errno = 0; PyFPE_START_PROTECT("complex function", goto exit);
617 _return_value = cmath_tanh_impl(module, z);
618 PyFPE_END_PROTECT(_return_value);
619 if (errno == EDOM) {
620 PyErr_SetString(PyExc_ValueError, "math domain error");
621 goto exit;
622 }
623 else if (errno == ERANGE) {
624 PyErr_SetString(PyExc_OverflowError, "math range error");
625 goto exit;
626 }
627 else {
628 return_value = PyComplex_FromCComplex(_return_value);
629 }
630
631exit:
632 return return_value;
633}
634
635PyDoc_STRVAR(cmath_log__doc__,
636"log($module, x, y_obj=None, /)\n"
637"--\n"
638"\n"
639"The logarithm of z to the given base.\n"
640"\n"
641"If the base not specified, returns the natural logarithm (base e) of z.");
642
643#define CMATH_LOG_METHODDEF \
644 {"log", (PyCFunction)cmath_log, METH_VARARGS, cmath_log__doc__},
645
646static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300647cmath_log_impl(PyObject *module, Py_complex x, PyObject *y_obj);
Brett Cannonb0fc4902014-10-14 17:37:02 -0400648
649static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300650cmath_log(PyObject *module, PyObject *args)
Brett Cannonb0fc4902014-10-14 17:37:02 -0400651{
652 PyObject *return_value = NULL;
653 Py_complex x;
654 PyObject *y_obj = NULL;
655
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300656 if (!PyArg_ParseTuple(args, "D|O:log",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300657 &x, &y_obj)) {
Brett Cannonb0fc4902014-10-14 17:37:02 -0400658 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300659 }
Brett Cannonb0fc4902014-10-14 17:37:02 -0400660 return_value = cmath_log_impl(module, x, y_obj);
661
662exit:
663 return return_value;
664}
665
666PyDoc_STRVAR(cmath_phase__doc__,
667"phase($module, z, /)\n"
668"--\n"
669"\n"
670"Return argument, also known as the phase angle, of a complex.");
671
672#define CMATH_PHASE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300673 {"phase", (PyCFunction)cmath_phase, METH_O, cmath_phase__doc__},
Brett Cannonb0fc4902014-10-14 17:37:02 -0400674
675static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300676cmath_phase_impl(PyObject *module, Py_complex z);
Brett Cannonb0fc4902014-10-14 17:37:02 -0400677
678static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300679cmath_phase(PyObject *module, PyObject *arg)
Brett Cannonb0fc4902014-10-14 17:37:02 -0400680{
681 PyObject *return_value = NULL;
682 Py_complex z;
683
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300684 if (!PyArg_Parse(arg, "D:phase", &z)) {
Brett Cannonb0fc4902014-10-14 17:37:02 -0400685 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300686 }
Brett Cannonb0fc4902014-10-14 17:37:02 -0400687 return_value = cmath_phase_impl(module, z);
688
689exit:
690 return return_value;
691}
692
693PyDoc_STRVAR(cmath_polar__doc__,
694"polar($module, z, /)\n"
695"--\n"
696"\n"
697"Convert a complex from rectangular coordinates to polar coordinates.\n"
698"\n"
699"r is the distance from 0 and phi the phase angle.");
700
701#define CMATH_POLAR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300702 {"polar", (PyCFunction)cmath_polar, METH_O, cmath_polar__doc__},
Brett Cannonb0fc4902014-10-14 17:37:02 -0400703
704static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300705cmath_polar_impl(PyObject *module, Py_complex z);
Brett Cannonb0fc4902014-10-14 17:37:02 -0400706
707static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300708cmath_polar(PyObject *module, PyObject *arg)
Brett Cannonb0fc4902014-10-14 17:37:02 -0400709{
710 PyObject *return_value = NULL;
711 Py_complex z;
712
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300713 if (!PyArg_Parse(arg, "D:polar", &z)) {
Brett Cannonb0fc4902014-10-14 17:37:02 -0400714 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300715 }
Brett Cannonb0fc4902014-10-14 17:37:02 -0400716 return_value = cmath_polar_impl(module, z);
717
718exit:
719 return return_value;
720}
721
722PyDoc_STRVAR(cmath_rect__doc__,
723"rect($module, r, phi, /)\n"
724"--\n"
725"\n"
726"Convert from polar coordinates to rectangular coordinates.");
727
728#define CMATH_RECT_METHODDEF \
729 {"rect", (PyCFunction)cmath_rect, METH_VARARGS, cmath_rect__doc__},
730
731static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300732cmath_rect_impl(PyObject *module, double r, double phi);
Brett Cannonb0fc4902014-10-14 17:37:02 -0400733
734static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300735cmath_rect(PyObject *module, PyObject *args)
Brett Cannonb0fc4902014-10-14 17:37:02 -0400736{
737 PyObject *return_value = NULL;
738 double r;
739 double phi;
740
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300741 if (!PyArg_ParseTuple(args, "dd:rect",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300742 &r, &phi)) {
Brett Cannonb0fc4902014-10-14 17:37:02 -0400743 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300744 }
Brett Cannonb0fc4902014-10-14 17:37:02 -0400745 return_value = cmath_rect_impl(module, r, phi);
746
747exit:
748 return return_value;
749}
750
751PyDoc_STRVAR(cmath_isfinite__doc__,
752"isfinite($module, z, /)\n"
753"--\n"
754"\n"
755"Return True if both the real and imaginary parts of z are finite, else False.");
756
757#define CMATH_ISFINITE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300758 {"isfinite", (PyCFunction)cmath_isfinite, METH_O, cmath_isfinite__doc__},
Brett Cannonb0fc4902014-10-14 17:37:02 -0400759
760static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300761cmath_isfinite_impl(PyObject *module, Py_complex z);
Brett Cannonb0fc4902014-10-14 17:37:02 -0400762
763static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300764cmath_isfinite(PyObject *module, PyObject *arg)
Brett Cannonb0fc4902014-10-14 17:37:02 -0400765{
766 PyObject *return_value = NULL;
767 Py_complex z;
768
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300769 if (!PyArg_Parse(arg, "D:isfinite", &z)) {
Brett Cannonb0fc4902014-10-14 17:37:02 -0400770 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300771 }
Brett Cannonb0fc4902014-10-14 17:37:02 -0400772 return_value = cmath_isfinite_impl(module, z);
773
774exit:
775 return return_value;
776}
777
778PyDoc_STRVAR(cmath_isnan__doc__,
779"isnan($module, z, /)\n"
780"--\n"
781"\n"
782"Checks if the real or imaginary part of z not a number (NaN).");
783
784#define CMATH_ISNAN_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300785 {"isnan", (PyCFunction)cmath_isnan, METH_O, cmath_isnan__doc__},
Brett Cannonb0fc4902014-10-14 17:37:02 -0400786
787static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300788cmath_isnan_impl(PyObject *module, Py_complex z);
Brett Cannonb0fc4902014-10-14 17:37:02 -0400789
790static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300791cmath_isnan(PyObject *module, PyObject *arg)
Brett Cannonb0fc4902014-10-14 17:37:02 -0400792{
793 PyObject *return_value = NULL;
794 Py_complex z;
795
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300796 if (!PyArg_Parse(arg, "D:isnan", &z)) {
Brett Cannonb0fc4902014-10-14 17:37:02 -0400797 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300798 }
Brett Cannonb0fc4902014-10-14 17:37:02 -0400799 return_value = cmath_isnan_impl(module, z);
800
801exit:
802 return return_value;
803}
804
805PyDoc_STRVAR(cmath_isinf__doc__,
806"isinf($module, z, /)\n"
807"--\n"
808"\n"
809"Checks if the real or imaginary part of z is infinite.");
810
811#define CMATH_ISINF_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300812 {"isinf", (PyCFunction)cmath_isinf, METH_O, cmath_isinf__doc__},
Brett Cannonb0fc4902014-10-14 17:37:02 -0400813
814static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300815cmath_isinf_impl(PyObject *module, Py_complex z);
Brett Cannonb0fc4902014-10-14 17:37:02 -0400816
817static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300818cmath_isinf(PyObject *module, PyObject *arg)
Brett Cannonb0fc4902014-10-14 17:37:02 -0400819{
820 PyObject *return_value = NULL;
821 Py_complex z;
822
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300823 if (!PyArg_Parse(arg, "D:isinf", &z)) {
Brett Cannonb0fc4902014-10-14 17:37:02 -0400824 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300825 }
Brett Cannonb0fc4902014-10-14 17:37:02 -0400826 return_value = cmath_isinf_impl(module, z);
827
828exit:
829 return return_value;
830}
Tal Einatd5519ed2015-05-31 22:05:00 +0300831
832PyDoc_STRVAR(cmath_isclose__doc__,
833"isclose($module, /, a, b, *, rel_tol=1e-09, abs_tol=0.0)\n"
834"--\n"
835"\n"
836"Determine whether two complex numbers are close in value.\n"
837"\n"
838" rel_tol\n"
839" maximum difference for being considered \"close\", relative to the\n"
840" magnitude of the input values\n"
841" abs_tol\n"
842" maximum difference for being considered \"close\", regardless of the\n"
843" magnitude of the input values\n"
844"\n"
845"Return True if a is close in value to b, and False otherwise.\n"
846"\n"
847"For the values to be considered close, the difference between them must be\n"
848"smaller than at least one of the tolerances.\n"
849"\n"
850"-inf, inf and NaN behave similarly to the IEEE 754 Standard. That is, NaN is\n"
851"not close to anything, even itself. inf and -inf are only close to themselves.");
852
853#define CMATH_ISCLOSE_METHODDEF \
854 {"isclose", (PyCFunction)cmath_isclose, METH_VARARGS|METH_KEYWORDS, cmath_isclose__doc__},
855
856static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300857cmath_isclose_impl(PyObject *module, Py_complex a, Py_complex b,
Tal Einatd5519ed2015-05-31 22:05:00 +0300858 double rel_tol, double abs_tol);
859
860static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300861cmath_isclose(PyObject *module, PyObject *args, PyObject *kwargs)
Tal Einatd5519ed2015-05-31 22:05:00 +0300862{
863 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300864 static const char * const _keywords[] = {"a", "b", "rel_tol", "abs_tol", NULL};
865 static _PyArg_Parser _parser = {"DD|$dd:isclose", _keywords, 0};
Tal Einatd5519ed2015-05-31 22:05:00 +0300866 Py_complex a;
867 Py_complex b;
868 double rel_tol = 1e-09;
869 double abs_tol = 0.0;
870 int _return_value;
871
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300872 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300873 &a, &b, &rel_tol, &abs_tol)) {
Tal Einatd5519ed2015-05-31 22:05:00 +0300874 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300875 }
Tal Einatd5519ed2015-05-31 22:05:00 +0300876 _return_value = cmath_isclose_impl(module, a, b, rel_tol, abs_tol);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300877 if ((_return_value == -1) && PyErr_Occurred()) {
Tal Einatd5519ed2015-05-31 22:05:00 +0300878 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300879 }
Tal Einatd5519ed2015-05-31 22:05:00 +0300880 return_value = PyBool_FromLong((long)_return_value);
881
882exit:
883 return return_value;
884}
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300885/*[clinic end generated code: output=aa2e77ca9fc26928 input=a9049054013a1b77]*/