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 |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 15 | cmath_acos_impl(PyObject *module, Py_complex z); |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 16 | |
| 17 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 18 | cmath_acos(PyObject *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 | 5dee655 | 2016-06-09 16:16:06 +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; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 26 | } |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 27 | /* 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 | |
| 43 | exit: |
| 44 | return return_value; |
| 45 | } |
| 46 | |
| 47 | PyDoc_STRVAR(cmath_acosh__doc__, |
| 48 | "acosh($module, z, /)\n" |
| 49 | "--\n" |
| 50 | "\n" |
Mark Dickinson | cc8617b | 2015-01-11 13:22:44 +0000 | [diff] [blame] | 51 | "Return the inverse hyperbolic cosine of z."); |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 52 | |
| 53 | #define CMATH_ACOSH_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 54 | {"acosh", (PyCFunction)cmath_acosh, METH_O, cmath_acosh__doc__}, |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 55 | |
| 56 | static Py_complex |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 57 | cmath_acosh_impl(PyObject *module, Py_complex z); |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 58 | |
| 59 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 60 | cmath_acosh(PyObject *module, PyObject *arg) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 61 | { |
| 62 | PyObject *return_value = NULL; |
| 63 | Py_complex z; |
| 64 | Py_complex _return_value; |
| 65 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 66 | if (!PyArg_Parse(arg, "D:acosh", &z)) { |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 67 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 68 | } |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 69 | /* 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 | |
| 85 | exit: |
| 86 | return return_value; |
| 87 | } |
| 88 | |
| 89 | PyDoc_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 Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 96 | {"asin", (PyCFunction)cmath_asin, METH_O, cmath_asin__doc__}, |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 97 | |
| 98 | static Py_complex |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 99 | cmath_asin_impl(PyObject *module, Py_complex z); |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 100 | |
| 101 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 102 | cmath_asin(PyObject *module, PyObject *arg) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 103 | { |
| 104 | PyObject *return_value = NULL; |
| 105 | Py_complex z; |
| 106 | Py_complex _return_value; |
| 107 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 108 | if (!PyArg_Parse(arg, "D:asin", &z)) { |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 109 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 110 | } |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 111 | /* 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 | |
| 127 | exit: |
| 128 | return return_value; |
| 129 | } |
| 130 | |
| 131 | PyDoc_STRVAR(cmath_asinh__doc__, |
| 132 | "asinh($module, z, /)\n" |
| 133 | "--\n" |
| 134 | "\n" |
Mark Dickinson | cc8617b | 2015-01-11 13:22:44 +0000 | [diff] [blame] | 135 | "Return the inverse hyperbolic sine of z."); |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 136 | |
| 137 | #define CMATH_ASINH_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 138 | {"asinh", (PyCFunction)cmath_asinh, METH_O, cmath_asinh__doc__}, |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 139 | |
| 140 | static Py_complex |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 141 | cmath_asinh_impl(PyObject *module, Py_complex z); |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 142 | |
| 143 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 144 | cmath_asinh(PyObject *module, PyObject *arg) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 145 | { |
| 146 | PyObject *return_value = NULL; |
| 147 | Py_complex z; |
| 148 | Py_complex _return_value; |
| 149 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 150 | if (!PyArg_Parse(arg, "D:asinh", &z)) { |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 151 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 152 | } |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 153 | /* 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 | |
| 169 | exit: |
| 170 | return return_value; |
| 171 | } |
| 172 | |
| 173 | PyDoc_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 Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 180 | {"atan", (PyCFunction)cmath_atan, METH_O, cmath_atan__doc__}, |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 181 | |
| 182 | static Py_complex |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 183 | cmath_atan_impl(PyObject *module, Py_complex z); |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 184 | |
| 185 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 186 | cmath_atan(PyObject *module, PyObject *arg) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 187 | { |
| 188 | PyObject *return_value = NULL; |
| 189 | Py_complex z; |
| 190 | Py_complex _return_value; |
| 191 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 192 | if (!PyArg_Parse(arg, "D:atan", &z)) { |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 193 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 194 | } |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 195 | /* 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 | |
| 211 | exit: |
| 212 | return return_value; |
| 213 | } |
| 214 | |
| 215 | PyDoc_STRVAR(cmath_atanh__doc__, |
| 216 | "atanh($module, z, /)\n" |
| 217 | "--\n" |
| 218 | "\n" |
Mark Dickinson | cc8617b | 2015-01-11 13:22:44 +0000 | [diff] [blame] | 219 | "Return the inverse hyperbolic tangent of z."); |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 220 | |
| 221 | #define CMATH_ATANH_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 222 | {"atanh", (PyCFunction)cmath_atanh, METH_O, cmath_atanh__doc__}, |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 223 | |
| 224 | static Py_complex |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 225 | cmath_atanh_impl(PyObject *module, Py_complex z); |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 226 | |
| 227 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 228 | cmath_atanh(PyObject *module, PyObject *arg) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 229 | { |
| 230 | PyObject *return_value = NULL; |
| 231 | Py_complex z; |
| 232 | Py_complex _return_value; |
| 233 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 234 | if (!PyArg_Parse(arg, "D:atanh", &z)) { |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 235 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 236 | } |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 237 | /* 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 | |
| 253 | exit: |
| 254 | return return_value; |
| 255 | } |
| 256 | |
| 257 | PyDoc_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 Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 264 | {"cos", (PyCFunction)cmath_cos, METH_O, cmath_cos__doc__}, |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 265 | |
| 266 | static Py_complex |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 267 | cmath_cos_impl(PyObject *module, Py_complex z); |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 268 | |
| 269 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 270 | cmath_cos(PyObject *module, PyObject *arg) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 271 | { |
| 272 | PyObject *return_value = NULL; |
| 273 | Py_complex z; |
| 274 | Py_complex _return_value; |
| 275 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 276 | if (!PyArg_Parse(arg, "D:cos", &z)) { |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 277 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 278 | } |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 279 | /* 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 | |
| 295 | exit: |
| 296 | return return_value; |
| 297 | } |
| 298 | |
| 299 | PyDoc_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 Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 306 | {"cosh", (PyCFunction)cmath_cosh, METH_O, cmath_cosh__doc__}, |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 307 | |
| 308 | static Py_complex |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 309 | cmath_cosh_impl(PyObject *module, Py_complex z); |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 310 | |
| 311 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 312 | cmath_cosh(PyObject *module, PyObject *arg) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 313 | { |
| 314 | PyObject *return_value = NULL; |
| 315 | Py_complex z; |
| 316 | Py_complex _return_value; |
| 317 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 318 | if (!PyArg_Parse(arg, "D:cosh", &z)) { |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 319 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 320 | } |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 321 | /* 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 | |
| 337 | exit: |
| 338 | return return_value; |
| 339 | } |
| 340 | |
| 341 | PyDoc_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 Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 348 | {"exp", (PyCFunction)cmath_exp, METH_O, cmath_exp__doc__}, |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 349 | |
| 350 | static Py_complex |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 351 | cmath_exp_impl(PyObject *module, Py_complex z); |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 352 | |
| 353 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 354 | cmath_exp(PyObject *module, PyObject *arg) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 355 | { |
| 356 | PyObject *return_value = NULL; |
| 357 | Py_complex z; |
| 358 | Py_complex _return_value; |
| 359 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 360 | if (!PyArg_Parse(arg, "D:exp", &z)) { |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 361 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 362 | } |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 363 | /* 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 | |
| 379 | exit: |
| 380 | return return_value; |
| 381 | } |
| 382 | |
| 383 | PyDoc_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 Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 390 | {"log10", (PyCFunction)cmath_log10, METH_O, cmath_log10__doc__}, |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 391 | |
| 392 | static Py_complex |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 393 | cmath_log10_impl(PyObject *module, Py_complex z); |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 394 | |
| 395 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 396 | cmath_log10(PyObject *module, PyObject *arg) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 397 | { |
| 398 | PyObject *return_value = NULL; |
| 399 | Py_complex z; |
| 400 | Py_complex _return_value; |
| 401 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 402 | if (!PyArg_Parse(arg, "D:log10", &z)) { |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 403 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 404 | } |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 405 | /* 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 | |
| 421 | exit: |
| 422 | return return_value; |
| 423 | } |
| 424 | |
| 425 | PyDoc_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 Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 432 | {"sin", (PyCFunction)cmath_sin, METH_O, cmath_sin__doc__}, |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 433 | |
| 434 | static Py_complex |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 435 | cmath_sin_impl(PyObject *module, Py_complex z); |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 436 | |
| 437 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 438 | cmath_sin(PyObject *module, PyObject *arg) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 439 | { |
| 440 | PyObject *return_value = NULL; |
| 441 | Py_complex z; |
| 442 | Py_complex _return_value; |
| 443 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 444 | if (!PyArg_Parse(arg, "D:sin", &z)) { |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 445 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 446 | } |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 447 | /* 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 | |
| 463 | exit: |
| 464 | return return_value; |
| 465 | } |
| 466 | |
| 467 | PyDoc_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 Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 474 | {"sinh", (PyCFunction)cmath_sinh, METH_O, cmath_sinh__doc__}, |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 475 | |
| 476 | static Py_complex |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 477 | cmath_sinh_impl(PyObject *module, Py_complex z); |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 478 | |
| 479 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 480 | cmath_sinh(PyObject *module, PyObject *arg) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 481 | { |
| 482 | PyObject *return_value = NULL; |
| 483 | Py_complex z; |
| 484 | Py_complex _return_value; |
| 485 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 486 | if (!PyArg_Parse(arg, "D:sinh", &z)) { |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 487 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 488 | } |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 489 | /* 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 | |
| 505 | exit: |
| 506 | return return_value; |
| 507 | } |
| 508 | |
| 509 | PyDoc_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 Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 516 | {"sqrt", (PyCFunction)cmath_sqrt, METH_O, cmath_sqrt__doc__}, |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 517 | |
| 518 | static Py_complex |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 519 | cmath_sqrt_impl(PyObject *module, Py_complex z); |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 520 | |
| 521 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 522 | cmath_sqrt(PyObject *module, PyObject *arg) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 523 | { |
| 524 | PyObject *return_value = NULL; |
| 525 | Py_complex z; |
| 526 | Py_complex _return_value; |
| 527 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 528 | if (!PyArg_Parse(arg, "D:sqrt", &z)) { |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 529 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 530 | } |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 531 | /* 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 | |
| 547 | exit: |
| 548 | return return_value; |
| 549 | } |
| 550 | |
| 551 | PyDoc_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 Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 558 | {"tan", (PyCFunction)cmath_tan, METH_O, cmath_tan__doc__}, |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 559 | |
| 560 | static Py_complex |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 561 | cmath_tan_impl(PyObject *module, Py_complex z); |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 562 | |
| 563 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 564 | cmath_tan(PyObject *module, PyObject *arg) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 565 | { |
| 566 | PyObject *return_value = NULL; |
| 567 | Py_complex z; |
| 568 | Py_complex _return_value; |
| 569 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 570 | if (!PyArg_Parse(arg, "D:tan", &z)) { |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 571 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 572 | } |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 573 | /* 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 | |
| 589 | exit: |
| 590 | return return_value; |
| 591 | } |
| 592 | |
| 593 | PyDoc_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 Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 600 | {"tanh", (PyCFunction)cmath_tanh, METH_O, cmath_tanh__doc__}, |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 601 | |
| 602 | static Py_complex |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 603 | cmath_tanh_impl(PyObject *module, Py_complex z); |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 604 | |
| 605 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 606 | cmath_tanh(PyObject *module, PyObject *arg) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 607 | { |
| 608 | PyObject *return_value = NULL; |
| 609 | Py_complex z; |
| 610 | Py_complex _return_value; |
| 611 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 612 | if (!PyArg_Parse(arg, "D:tanh", &z)) { |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 613 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 614 | } |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 615 | /* 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 | |
| 631 | exit: |
| 632 | return return_value; |
| 633 | } |
| 634 | |
| 635 | PyDoc_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 \ |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 644 | {"log", (PyCFunction)cmath_log, METH_FASTCALL, cmath_log__doc__}, |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 645 | |
| 646 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 647 | cmath_log_impl(PyObject *module, Py_complex x, PyObject *y_obj); |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 648 | |
| 649 | static PyObject * |
Serhiy Storchaka | 6969eaf | 2017-07-03 21:20:15 +0300 | [diff] [blame^] | 650 | cmath_log(PyObject *module, PyObject **args, Py_ssize_t nargs) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 651 | { |
| 652 | PyObject *return_value = NULL; |
| 653 | Py_complex x; |
| 654 | PyObject *y_obj = NULL; |
| 655 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 656 | if (!_PyArg_ParseStack(args, nargs, "D|O:log", |
| 657 | &x, &y_obj)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 658 | goto exit; |
| 659 | } |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 660 | return_value = cmath_log_impl(module, x, y_obj); |
| 661 | |
| 662 | exit: |
| 663 | return return_value; |
| 664 | } |
| 665 | |
| 666 | PyDoc_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 Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 673 | {"phase", (PyCFunction)cmath_phase, METH_O, cmath_phase__doc__}, |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 674 | |
| 675 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 676 | cmath_phase_impl(PyObject *module, Py_complex z); |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 677 | |
| 678 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 679 | cmath_phase(PyObject *module, PyObject *arg) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 680 | { |
| 681 | PyObject *return_value = NULL; |
| 682 | Py_complex z; |
| 683 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 684 | if (!PyArg_Parse(arg, "D:phase", &z)) { |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 685 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 686 | } |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 687 | return_value = cmath_phase_impl(module, z); |
| 688 | |
| 689 | exit: |
| 690 | return return_value; |
| 691 | } |
| 692 | |
| 693 | PyDoc_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 Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 702 | {"polar", (PyCFunction)cmath_polar, METH_O, cmath_polar__doc__}, |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 703 | |
| 704 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 705 | cmath_polar_impl(PyObject *module, Py_complex z); |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 706 | |
| 707 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 708 | cmath_polar(PyObject *module, PyObject *arg) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 709 | { |
| 710 | PyObject *return_value = NULL; |
| 711 | Py_complex z; |
| 712 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 713 | if (!PyArg_Parse(arg, "D:polar", &z)) { |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 714 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 715 | } |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 716 | return_value = cmath_polar_impl(module, z); |
| 717 | |
| 718 | exit: |
| 719 | return return_value; |
| 720 | } |
| 721 | |
| 722 | PyDoc_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 \ |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 729 | {"rect", (PyCFunction)cmath_rect, METH_FASTCALL, cmath_rect__doc__}, |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 730 | |
| 731 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 732 | cmath_rect_impl(PyObject *module, double r, double phi); |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 733 | |
| 734 | static PyObject * |
Serhiy Storchaka | 6969eaf | 2017-07-03 21:20:15 +0300 | [diff] [blame^] | 735 | cmath_rect(PyObject *module, PyObject **args, Py_ssize_t nargs) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 736 | { |
| 737 | PyObject *return_value = NULL; |
| 738 | double r; |
| 739 | double phi; |
| 740 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 741 | if (!_PyArg_ParseStack(args, nargs, "dd:rect", |
| 742 | &r, &phi)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 743 | goto exit; |
| 744 | } |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 745 | return_value = cmath_rect_impl(module, r, phi); |
| 746 | |
| 747 | exit: |
| 748 | return return_value; |
| 749 | } |
| 750 | |
| 751 | PyDoc_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 Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 758 | {"isfinite", (PyCFunction)cmath_isfinite, METH_O, cmath_isfinite__doc__}, |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 759 | |
| 760 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 761 | cmath_isfinite_impl(PyObject *module, Py_complex z); |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 762 | |
| 763 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 764 | cmath_isfinite(PyObject *module, PyObject *arg) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 765 | { |
| 766 | PyObject *return_value = NULL; |
| 767 | Py_complex z; |
| 768 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 769 | if (!PyArg_Parse(arg, "D:isfinite", &z)) { |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 770 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 771 | } |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 772 | return_value = cmath_isfinite_impl(module, z); |
| 773 | |
| 774 | exit: |
| 775 | return return_value; |
| 776 | } |
| 777 | |
| 778 | PyDoc_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 Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 785 | {"isnan", (PyCFunction)cmath_isnan, METH_O, cmath_isnan__doc__}, |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 786 | |
| 787 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 788 | cmath_isnan_impl(PyObject *module, Py_complex z); |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 789 | |
| 790 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 791 | cmath_isnan(PyObject *module, PyObject *arg) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 792 | { |
| 793 | PyObject *return_value = NULL; |
| 794 | Py_complex z; |
| 795 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 796 | if (!PyArg_Parse(arg, "D:isnan", &z)) { |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 797 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 798 | } |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 799 | return_value = cmath_isnan_impl(module, z); |
| 800 | |
| 801 | exit: |
| 802 | return return_value; |
| 803 | } |
| 804 | |
| 805 | PyDoc_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 Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 812 | {"isinf", (PyCFunction)cmath_isinf, METH_O, cmath_isinf__doc__}, |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 813 | |
| 814 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 815 | cmath_isinf_impl(PyObject *module, Py_complex z); |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 816 | |
| 817 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 818 | cmath_isinf(PyObject *module, PyObject *arg) |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 819 | { |
| 820 | PyObject *return_value = NULL; |
| 821 | Py_complex z; |
| 822 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 823 | if (!PyArg_Parse(arg, "D:isinf", &z)) { |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 824 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 825 | } |
Brett Cannon | b0fc490 | 2014-10-14 17:37:02 -0400 | [diff] [blame] | 826 | return_value = cmath_isinf_impl(module, z); |
| 827 | |
| 828 | exit: |
| 829 | return return_value; |
| 830 | } |
Tal Einat | d5519ed | 2015-05-31 22:05:00 +0300 | [diff] [blame] | 831 | |
| 832 | PyDoc_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 \ |
Serhiy Storchaka | 6969eaf | 2017-07-03 21:20:15 +0300 | [diff] [blame^] | 854 | {"isclose", (PyCFunction)cmath_isclose, METH_FASTCALL|METH_KEYWORDS, cmath_isclose__doc__}, |
Tal Einat | d5519ed | 2015-05-31 22:05:00 +0300 | [diff] [blame] | 855 | |
| 856 | static int |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 857 | cmath_isclose_impl(PyObject *module, Py_complex a, Py_complex b, |
Tal Einat | d5519ed | 2015-05-31 22:05:00 +0300 | [diff] [blame] | 858 | double rel_tol, double abs_tol); |
| 859 | |
| 860 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 861 | cmath_isclose(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Tal Einat | d5519ed | 2015-05-31 22:05:00 +0300 | [diff] [blame] | 862 | { |
| 863 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 864 | static const char * const _keywords[] = {"a", "b", "rel_tol", "abs_tol", NULL}; |
| 865 | static _PyArg_Parser _parser = {"DD|$dd:isclose", _keywords, 0}; |
Tal Einat | d5519ed | 2015-05-31 22:05:00 +0300 | [diff] [blame] | 866 | Py_complex a; |
| 867 | Py_complex b; |
| 868 | double rel_tol = 1e-09; |
| 869 | double abs_tol = 0.0; |
| 870 | int _return_value; |
| 871 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 872 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 873 | &a, &b, &rel_tol, &abs_tol)) { |
Tal Einat | d5519ed | 2015-05-31 22:05:00 +0300 | [diff] [blame] | 874 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 875 | } |
Tal Einat | d5519ed | 2015-05-31 22:05:00 +0300 | [diff] [blame] | 876 | _return_value = cmath_isclose_impl(module, a, b, rel_tol, abs_tol); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 877 | if ((_return_value == -1) && PyErr_Occurred()) { |
Tal Einat | d5519ed | 2015-05-31 22:05:00 +0300 | [diff] [blame] | 878 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 879 | } |
Tal Einat | d5519ed | 2015-05-31 22:05:00 +0300 | [diff] [blame] | 880 | return_value = PyBool_FromLong((long)_return_value); |
| 881 | |
| 882 | exit: |
| 883 | return return_value; |
| 884 | } |
Serhiy Storchaka | 6969eaf | 2017-07-03 21:20:15 +0300 | [diff] [blame^] | 885 | /*[clinic end generated code: output=51ba28d27d10264e input=a9049054013a1b77]*/ |