Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 1 | /*[clinic input] |
| 2 | preserve |
| 3 | [clinic start generated code]*/ |
| 4 | |
| 5 | PyDoc_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 Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 12 | {"acos", (PyCFunction)cmath_acos, METH_O, cmath_acos__doc__}, |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 13 | |
| 14 | static Py_complex |
| 15 | cmath_acos_impl(PyModuleDef *module, Py_complex z); |
| 16 | |
| 17 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 18 | cmath_acos(PyModuleDef *module, PyObject *arg) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 19 | { |
| 20 | PyObject *return_value = NULL; |
| 21 | Py_complex z; |
| 22 | Py_complex _return_value; |
| 23 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 24 | if (!PyArg_Parse(arg, "D:acos", &z)) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 25 | 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 | |
| 42 | exit: |
| 43 | return return_value; |
| 44 | } |
| 45 | |
| 46 | PyDoc_STRVAR(cmath_acosh__doc__, |
| 47 | "acosh($module, z, /)\n" |
| 48 | "--\n" |
| 49 | "\n" |
Mark Dickinson | cc8617b | 2015-01-11 13:22:44 +0000 | [diff] [blame] | 50 | "Return the inverse hyperbolic cosine of z."); |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 51 | |
| 52 | #define CMATH_ACOSH_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 53 | {"acosh", (PyCFunction)cmath_acosh, METH_O, cmath_acosh__doc__}, |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 54 | |
| 55 | static Py_complex |
| 56 | cmath_acosh_impl(PyModuleDef *module, Py_complex z); |
| 57 | |
| 58 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 59 | cmath_acosh(PyModuleDef *module, PyObject *arg) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 60 | { |
| 61 | PyObject *return_value = NULL; |
| 62 | Py_complex z; |
| 63 | Py_complex _return_value; |
| 64 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 65 | if (!PyArg_Parse(arg, "D:acosh", &z)) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 66 | 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 | |
| 83 | exit: |
| 84 | return return_value; |
| 85 | } |
| 86 | |
| 87 | PyDoc_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 Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 94 | {"asin", (PyCFunction)cmath_asin, METH_O, cmath_asin__doc__}, |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 95 | |
| 96 | static Py_complex |
| 97 | cmath_asin_impl(PyModuleDef *module, Py_complex z); |
| 98 | |
| 99 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 100 | cmath_asin(PyModuleDef *module, PyObject *arg) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 101 | { |
| 102 | PyObject *return_value = NULL; |
| 103 | Py_complex z; |
| 104 | Py_complex _return_value; |
| 105 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 106 | if (!PyArg_Parse(arg, "D:asin", &z)) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 107 | 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 | |
| 124 | exit: |
| 125 | return return_value; |
| 126 | } |
| 127 | |
| 128 | PyDoc_STRVAR(cmath_asinh__doc__, |
| 129 | "asinh($module, z, /)\n" |
| 130 | "--\n" |
| 131 | "\n" |
Mark Dickinson | cc8617b | 2015-01-11 13:22:44 +0000 | [diff] [blame] | 132 | "Return the inverse hyperbolic sine of z."); |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 133 | |
| 134 | #define CMATH_ASINH_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 135 | {"asinh", (PyCFunction)cmath_asinh, METH_O, cmath_asinh__doc__}, |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 136 | |
| 137 | static Py_complex |
| 138 | cmath_asinh_impl(PyModuleDef *module, Py_complex z); |
| 139 | |
| 140 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 141 | cmath_asinh(PyModuleDef *module, PyObject *arg) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 142 | { |
| 143 | PyObject *return_value = NULL; |
| 144 | Py_complex z; |
| 145 | Py_complex _return_value; |
| 146 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 147 | if (!PyArg_Parse(arg, "D:asinh", &z)) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 148 | 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 | |
| 165 | exit: |
| 166 | return return_value; |
| 167 | } |
| 168 | |
| 169 | PyDoc_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 Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 176 | {"atan", (PyCFunction)cmath_atan, METH_O, cmath_atan__doc__}, |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 177 | |
| 178 | static Py_complex |
| 179 | cmath_atan_impl(PyModuleDef *module, Py_complex z); |
| 180 | |
| 181 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 182 | cmath_atan(PyModuleDef *module, PyObject *arg) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 183 | { |
| 184 | PyObject *return_value = NULL; |
| 185 | Py_complex z; |
| 186 | Py_complex _return_value; |
| 187 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 188 | if (!PyArg_Parse(arg, "D:atan", &z)) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 189 | 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 | |
| 206 | exit: |
| 207 | return return_value; |
| 208 | } |
| 209 | |
| 210 | PyDoc_STRVAR(cmath_atanh__doc__, |
| 211 | "atanh($module, z, /)\n" |
| 212 | "--\n" |
| 213 | "\n" |
Mark Dickinson | cc8617b | 2015-01-11 13:22:44 +0000 | [diff] [blame] | 214 | "Return the inverse hyperbolic tangent of z."); |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 215 | |
| 216 | #define CMATH_ATANH_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 217 | {"atanh", (PyCFunction)cmath_atanh, METH_O, cmath_atanh__doc__}, |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 218 | |
| 219 | static Py_complex |
| 220 | cmath_atanh_impl(PyModuleDef *module, Py_complex z); |
| 221 | |
| 222 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 223 | cmath_atanh(PyModuleDef *module, PyObject *arg) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 224 | { |
| 225 | PyObject *return_value = NULL; |
| 226 | Py_complex z; |
| 227 | Py_complex _return_value; |
| 228 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 229 | if (!PyArg_Parse(arg, "D:atanh", &z)) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 230 | 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 | |
| 247 | exit: |
| 248 | return return_value; |
| 249 | } |
| 250 | |
| 251 | PyDoc_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 Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 258 | {"cos", (PyCFunction)cmath_cos, METH_O, cmath_cos__doc__}, |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 259 | |
| 260 | static Py_complex |
| 261 | cmath_cos_impl(PyModuleDef *module, Py_complex z); |
| 262 | |
| 263 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 264 | cmath_cos(PyModuleDef *module, PyObject *arg) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 265 | { |
| 266 | PyObject *return_value = NULL; |
| 267 | Py_complex z; |
| 268 | Py_complex _return_value; |
| 269 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 270 | if (!PyArg_Parse(arg, "D:cos", &z)) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 271 | 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 | |
| 288 | exit: |
| 289 | return return_value; |
| 290 | } |
| 291 | |
| 292 | PyDoc_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 Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 299 | {"cosh", (PyCFunction)cmath_cosh, METH_O, cmath_cosh__doc__}, |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 300 | |
| 301 | static Py_complex |
| 302 | cmath_cosh_impl(PyModuleDef *module, Py_complex z); |
| 303 | |
| 304 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 305 | cmath_cosh(PyModuleDef *module, PyObject *arg) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 306 | { |
| 307 | PyObject *return_value = NULL; |
| 308 | Py_complex z; |
| 309 | Py_complex _return_value; |
| 310 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 311 | if (!PyArg_Parse(arg, "D:cosh", &z)) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 312 | 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 | |
| 329 | exit: |
| 330 | return return_value; |
| 331 | } |
| 332 | |
| 333 | PyDoc_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 Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 340 | {"exp", (PyCFunction)cmath_exp, METH_O, cmath_exp__doc__}, |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 341 | |
| 342 | static Py_complex |
| 343 | cmath_exp_impl(PyModuleDef *module, Py_complex z); |
| 344 | |
| 345 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 346 | cmath_exp(PyModuleDef *module, PyObject *arg) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 347 | { |
| 348 | PyObject *return_value = NULL; |
| 349 | Py_complex z; |
| 350 | Py_complex _return_value; |
| 351 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 352 | if (!PyArg_Parse(arg, "D:exp", &z)) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 353 | 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 | |
| 370 | exit: |
| 371 | return return_value; |
| 372 | } |
| 373 | |
| 374 | PyDoc_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 Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 381 | {"log10", (PyCFunction)cmath_log10, METH_O, cmath_log10__doc__}, |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 382 | |
| 383 | static Py_complex |
| 384 | cmath_log10_impl(PyModuleDef *module, Py_complex z); |
| 385 | |
| 386 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 387 | cmath_log10(PyModuleDef *module, PyObject *arg) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 388 | { |
| 389 | PyObject *return_value = NULL; |
| 390 | Py_complex z; |
| 391 | Py_complex _return_value; |
| 392 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 393 | if (!PyArg_Parse(arg, "D:log10", &z)) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 394 | 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 | |
| 411 | exit: |
| 412 | return return_value; |
| 413 | } |
| 414 | |
| 415 | PyDoc_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 Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 422 | {"sin", (PyCFunction)cmath_sin, METH_O, cmath_sin__doc__}, |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 423 | |
| 424 | static Py_complex |
| 425 | cmath_sin_impl(PyModuleDef *module, Py_complex z); |
| 426 | |
| 427 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 428 | cmath_sin(PyModuleDef *module, PyObject *arg) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 429 | { |
| 430 | PyObject *return_value = NULL; |
| 431 | Py_complex z; |
| 432 | Py_complex _return_value; |
| 433 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 434 | if (!PyArg_Parse(arg, "D:sin", &z)) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 435 | 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 | |
| 452 | exit: |
| 453 | return return_value; |
| 454 | } |
| 455 | |
| 456 | PyDoc_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 Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 463 | {"sinh", (PyCFunction)cmath_sinh, METH_O, cmath_sinh__doc__}, |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 464 | |
| 465 | static Py_complex |
| 466 | cmath_sinh_impl(PyModuleDef *module, Py_complex z); |
| 467 | |
| 468 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 469 | cmath_sinh(PyModuleDef *module, PyObject *arg) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 470 | { |
| 471 | PyObject *return_value = NULL; |
| 472 | Py_complex z; |
| 473 | Py_complex _return_value; |
| 474 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 475 | if (!PyArg_Parse(arg, "D:sinh", &z)) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 476 | 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 | |
| 493 | exit: |
| 494 | return return_value; |
| 495 | } |
| 496 | |
| 497 | PyDoc_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 Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 504 | {"sqrt", (PyCFunction)cmath_sqrt, METH_O, cmath_sqrt__doc__}, |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 505 | |
| 506 | static Py_complex |
| 507 | cmath_sqrt_impl(PyModuleDef *module, Py_complex z); |
| 508 | |
| 509 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 510 | cmath_sqrt(PyModuleDef *module, PyObject *arg) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 511 | { |
| 512 | PyObject *return_value = NULL; |
| 513 | Py_complex z; |
| 514 | Py_complex _return_value; |
| 515 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 516 | if (!PyArg_Parse(arg, "D:sqrt", &z)) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 517 | 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 | |
| 534 | exit: |
| 535 | return return_value; |
| 536 | } |
| 537 | |
| 538 | PyDoc_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 Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 545 | {"tan", (PyCFunction)cmath_tan, METH_O, cmath_tan__doc__}, |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 546 | |
| 547 | static Py_complex |
| 548 | cmath_tan_impl(PyModuleDef *module, Py_complex z); |
| 549 | |
| 550 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 551 | cmath_tan(PyModuleDef *module, PyObject *arg) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 552 | { |
| 553 | PyObject *return_value = NULL; |
| 554 | Py_complex z; |
| 555 | Py_complex _return_value; |
| 556 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 557 | if (!PyArg_Parse(arg, "D:tan", &z)) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 558 | 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 | |
| 575 | exit: |
| 576 | return return_value; |
| 577 | } |
| 578 | |
| 579 | PyDoc_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 Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 586 | {"tanh", (PyCFunction)cmath_tanh, METH_O, cmath_tanh__doc__}, |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 587 | |
| 588 | static Py_complex |
| 589 | cmath_tanh_impl(PyModuleDef *module, Py_complex z); |
| 590 | |
| 591 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 592 | cmath_tanh(PyModuleDef *module, PyObject *arg) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 593 | { |
| 594 | PyObject *return_value = NULL; |
| 595 | Py_complex z; |
| 596 | Py_complex _return_value; |
| 597 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 598 | if (!PyArg_Parse(arg, "D:tanh", &z)) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 599 | 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 | |
| 616 | exit: |
| 617 | return return_value; |
| 618 | } |
| 619 | |
| 620 | PyDoc_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 | |
| 631 | static PyObject * |
| 632 | cmath_log_impl(PyModuleDef *module, Py_complex x, PyObject *y_obj); |
| 633 | |
| 634 | static PyObject * |
| 635 | cmath_log(PyModuleDef *module, PyObject *args) |
| 636 | { |
| 637 | PyObject *return_value = NULL; |
| 638 | Py_complex x; |
| 639 | PyObject *y_obj = NULL; |
| 640 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 641 | if (!PyArg_ParseTuple(args, "D|O:log", |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 642 | &x, &y_obj)) |
| 643 | goto exit; |
| 644 | return_value = cmath_log_impl(module, x, y_obj); |
| 645 | |
| 646 | exit: |
| 647 | return return_value; |
| 648 | } |
| 649 | |
| 650 | PyDoc_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 Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 657 | {"phase", (PyCFunction)cmath_phase, METH_O, cmath_phase__doc__}, |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 658 | |
| 659 | static PyObject * |
| 660 | cmath_phase_impl(PyModuleDef *module, Py_complex z); |
| 661 | |
| 662 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 663 | cmath_phase(PyModuleDef *module, PyObject *arg) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 664 | { |
| 665 | PyObject *return_value = NULL; |
| 666 | Py_complex z; |
| 667 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 668 | if (!PyArg_Parse(arg, "D:phase", &z)) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 669 | goto exit; |
| 670 | return_value = cmath_phase_impl(module, z); |
| 671 | |
| 672 | exit: |
| 673 | return return_value; |
| 674 | } |
| 675 | |
| 676 | PyDoc_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 Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 685 | {"polar", (PyCFunction)cmath_polar, METH_O, cmath_polar__doc__}, |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 686 | |
| 687 | static PyObject * |
| 688 | cmath_polar_impl(PyModuleDef *module, Py_complex z); |
| 689 | |
| 690 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 691 | cmath_polar(PyModuleDef *module, PyObject *arg) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 692 | { |
| 693 | PyObject *return_value = NULL; |
| 694 | Py_complex z; |
| 695 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 696 | if (!PyArg_Parse(arg, "D:polar", &z)) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 697 | goto exit; |
| 698 | return_value = cmath_polar_impl(module, z); |
| 699 | |
| 700 | exit: |
| 701 | return return_value; |
| 702 | } |
| 703 | |
| 704 | PyDoc_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 | |
| 713 | static PyObject * |
| 714 | cmath_rect_impl(PyModuleDef *module, double r, double phi); |
| 715 | |
| 716 | static PyObject * |
| 717 | cmath_rect(PyModuleDef *module, PyObject *args) |
| 718 | { |
| 719 | PyObject *return_value = NULL; |
| 720 | double r; |
| 721 | double phi; |
| 722 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 723 | if (!PyArg_ParseTuple(args, "dd:rect", |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 724 | &r, &phi)) |
| 725 | goto exit; |
| 726 | return_value = cmath_rect_impl(module, r, phi); |
| 727 | |
| 728 | exit: |
| 729 | return return_value; |
| 730 | } |
| 731 | |
| 732 | PyDoc_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 Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 739 | {"isfinite", (PyCFunction)cmath_isfinite, METH_O, cmath_isfinite__doc__}, |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 740 | |
| 741 | static PyObject * |
| 742 | cmath_isfinite_impl(PyModuleDef *module, Py_complex z); |
| 743 | |
| 744 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 745 | cmath_isfinite(PyModuleDef *module, PyObject *arg) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 746 | { |
| 747 | PyObject *return_value = NULL; |
| 748 | Py_complex z; |
| 749 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 750 | if (!PyArg_Parse(arg, "D:isfinite", &z)) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 751 | goto exit; |
| 752 | return_value = cmath_isfinite_impl(module, z); |
| 753 | |
| 754 | exit: |
| 755 | return return_value; |
| 756 | } |
| 757 | |
| 758 | PyDoc_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 Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 765 | {"isnan", (PyCFunction)cmath_isnan, METH_O, cmath_isnan__doc__}, |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 766 | |
| 767 | static PyObject * |
| 768 | cmath_isnan_impl(PyModuleDef *module, Py_complex z); |
| 769 | |
| 770 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 771 | cmath_isnan(PyModuleDef *module, PyObject *arg) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 772 | { |
| 773 | PyObject *return_value = NULL; |
| 774 | Py_complex z; |
| 775 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 776 | if (!PyArg_Parse(arg, "D:isnan", &z)) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 777 | goto exit; |
| 778 | return_value = cmath_isnan_impl(module, z); |
| 779 | |
| 780 | exit: |
| 781 | return return_value; |
| 782 | } |
| 783 | |
| 784 | PyDoc_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 Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 791 | {"isinf", (PyCFunction)cmath_isinf, METH_O, cmath_isinf__doc__}, |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 792 | |
| 793 | static PyObject * |
| 794 | cmath_isinf_impl(PyModuleDef *module, Py_complex z); |
| 795 | |
| 796 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 797 | cmath_isinf(PyModuleDef *module, PyObject *arg) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 798 | { |
| 799 | PyObject *return_value = NULL; |
| 800 | Py_complex z; |
| 801 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 802 | if (!PyArg_Parse(arg, "D:isinf", &z)) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 803 | goto exit; |
| 804 | return_value = cmath_isinf_impl(module, z); |
| 805 | |
| 806 | exit: |
| 807 | return return_value; |
| 808 | } |
Tal Einat | d5519ed | 2015-05-31 22:05:00 +0300 | [diff] [blame] | 809 | |
| 810 | PyDoc_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 | |
| 834 | static int |
| 835 | cmath_isclose_impl(PyModuleDef *module, Py_complex a, Py_complex b, |
| 836 | double rel_tol, double abs_tol); |
| 837 | |
| 838 | static PyObject * |
| 839 | cmath_isclose(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 840 | { |
| 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 | |
| 857 | exit: |
| 858 | return return_value; |
| 859 | } |
| 860 | /*[clinic end generated code: output=229e9c48c9d27362 input=a9049054013a1b77]*/ |