1/*[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 \ 12 {"acos", (PyCFunction)cmath_acos, METH_O, cmath_acos__doc__}, 13 14static Py_complex 15cmath_acos_impl(PyObject *module, Py_complex z); 16 17static PyObject * 18cmath_acos(PyObject *module, PyObject *arg) 19{ 20 PyObject *return_value = NULL; 21 Py_complex z; 22 Py_complex _return_value; 23 24 z = PyComplex_AsCComplex(arg); 25 if (PyErr_Occurred()) { 26 goto exit; 27 } 28 /* modifications for z */ 29 errno = 0; 30 _return_value = cmath_acos_impl(module, z); 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" 51"Return the inverse hyperbolic cosine of z."); 52 53#define CMATH_ACOSH_METHODDEF \ 54 {"acosh", (PyCFunction)cmath_acosh, METH_O, cmath_acosh__doc__}, 55 56static Py_complex 57cmath_acosh_impl(PyObject *module, Py_complex z); 58 59static PyObject * 60cmath_acosh(PyObject *module, PyObject *arg) 61{ 62 PyObject *return_value = NULL; 63 Py_complex z; 64 Py_complex _return_value; 65 66 z = PyComplex_AsCComplex(arg); 67 if (PyErr_Occurred()) { 68 goto exit; 69 } 70 /* modifications for z */ 71 errno = 0; 72 _return_value = cmath_acosh_impl(module, z); 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 \ 96 {"asin", (PyCFunction)cmath_asin, METH_O, cmath_asin__doc__}, 97 98static Py_complex 99cmath_asin_impl(PyObject *module, Py_complex z); 100 101static PyObject * 102cmath_asin(PyObject *module, PyObject *arg) 103{ 104 PyObject *return_value = NULL; 105 Py_complex z; 106 Py_complex _return_value; 107 108 z = PyComplex_AsCComplex(arg); 109 if (PyErr_Occurred()) { 110 goto exit; 111 } 112 /* modifications for z */ 113 errno = 0; 114 _return_value = cmath_asin_impl(module, z); 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" 135"Return the inverse hyperbolic sine of z."); 136 137#define CMATH_ASINH_METHODDEF \ 138 {"asinh", (PyCFunction)cmath_asinh, METH_O, cmath_asinh__doc__}, 139 140static Py_complex 141cmath_asinh_impl(PyObject *module, Py_complex z); 142 143static PyObject * 144cmath_asinh(PyObject *module, PyObject *arg) 145{ 146 PyObject *return_value = NULL; 147 Py_complex z; 148 Py_complex _return_value; 149 150 z = PyComplex_AsCComplex(arg); 151 if (PyErr_Occurred()) { 152 goto exit; 153 } 154 /* modifications for z */ 155 errno = 0; 156 _return_value = cmath_asinh_impl(module, z); 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 \ 180 {"atan", (PyCFunction)cmath_atan, METH_O, cmath_atan__doc__}, 181 182static Py_complex 183cmath_atan_impl(PyObject *module, Py_complex z); 184 185static PyObject * 186cmath_atan(PyObject *module, PyObject *arg) 187{ 188 PyObject *return_value = NULL; 189 Py_complex z; 190 Py_complex _return_value; 191 192 z = PyComplex_AsCComplex(arg); 193 if (PyErr_Occurred()) { 194 goto exit; 195 } 196 /* modifications for z */ 197 errno = 0; 198 _return_value = cmath_atan_impl(module, z); 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" 219"Return the inverse hyperbolic tangent of z."); 220 221#define CMATH_ATANH_METHODDEF \ 222 {"atanh", (PyCFunction)cmath_atanh, METH_O, cmath_atanh__doc__}, 223 224static Py_complex 225cmath_atanh_impl(PyObject *module, Py_complex z); 226 227static PyObject * 228cmath_atanh(PyObject *module, PyObject *arg) 229{ 230 PyObject *return_value = NULL; 231 Py_complex z; 232 Py_complex _return_value; 233 234 z = PyComplex_AsCComplex(arg); 235 if (PyErr_Occurred()) { 236 goto exit; 237 } 238 /* modifications for z */ 239 errno = 0; 240 _return_value = cmath_atanh_impl(module, z); 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 \ 264 {"cos", (PyCFunction)cmath_cos, METH_O, cmath_cos__doc__}, 265 266static Py_complex 267cmath_cos_impl(PyObject *module, Py_complex z); 268 269static PyObject * 270cmath_cos(PyObject *module, PyObject *arg) 271{ 272 PyObject *return_value = NULL; 273 Py_complex z; 274 Py_complex _return_value; 275 276 z = PyComplex_AsCComplex(arg); 277 if (PyErr_Occurred()) { 278 goto exit; 279 } 280 /* modifications for z */ 281 errno = 0; 282 _return_value = cmath_cos_impl(module, z); 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 \ 306 {"cosh", (PyCFunction)cmath_cosh, METH_O, cmath_cosh__doc__}, 307 308static Py_complex 309cmath_cosh_impl(PyObject *module, Py_complex z); 310 311static PyObject * 312cmath_cosh(PyObject *module, PyObject *arg) 313{ 314 PyObject *return_value = NULL; 315 Py_complex z; 316 Py_complex _return_value; 317 318 z = PyComplex_AsCComplex(arg); 319 if (PyErr_Occurred()) { 320 goto exit; 321 } 322 /* modifications for z */ 323 errno = 0; 324 _return_value = cmath_cosh_impl(module, z); 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 \ 348 {"exp", (PyCFunction)cmath_exp, METH_O, cmath_exp__doc__}, 349 350static Py_complex 351cmath_exp_impl(PyObject *module, Py_complex z); 352 353static PyObject * 354cmath_exp(PyObject *module, PyObject *arg) 355{ 356 PyObject *return_value = NULL; 357 Py_complex z; 358 Py_complex _return_value; 359 360 z = PyComplex_AsCComplex(arg); 361 if (PyErr_Occurred()) { 362 goto exit; 363 } 364 /* modifications for z */ 365 errno = 0; 366 _return_value = cmath_exp_impl(module, z); 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 \ 390 {"log10", (PyCFunction)cmath_log10, METH_O, cmath_log10__doc__}, 391 392static Py_complex 393cmath_log10_impl(PyObject *module, Py_complex z); 394 395static PyObject * 396cmath_log10(PyObject *module, PyObject *arg) 397{ 398 PyObject *return_value = NULL; 399 Py_complex z; 400 Py_complex _return_value; 401 402 z = PyComplex_AsCComplex(arg); 403 if (PyErr_Occurred()) { 404 goto exit; 405 } 406 /* modifications for z */ 407 errno = 0; 408 _return_value = cmath_log10_impl(module, z); 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 \ 432 {"sin", (PyCFunction)cmath_sin, METH_O, cmath_sin__doc__}, 433 434static Py_complex 435cmath_sin_impl(PyObject *module, Py_complex z); 436 437static PyObject * 438cmath_sin(PyObject *module, PyObject *arg) 439{ 440 PyObject *return_value = NULL; 441 Py_complex z; 442 Py_complex _return_value; 443 444 z = PyComplex_AsCComplex(arg); 445 if (PyErr_Occurred()) { 446 goto exit; 447 } 448 /* modifications for z */ 449 errno = 0; 450 _return_value = cmath_sin_impl(module, z); 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 \ 474 {"sinh", (PyCFunction)cmath_sinh, METH_O, cmath_sinh__doc__}, 475 476static Py_complex 477cmath_sinh_impl(PyObject *module, Py_complex z); 478 479static PyObject * 480cmath_sinh(PyObject *module, PyObject *arg) 481{ 482 PyObject *return_value = NULL; 483 Py_complex z; 484 Py_complex _return_value; 485 486 z = PyComplex_AsCComplex(arg); 487 if (PyErr_Occurred()) { 488 goto exit; 489 } 490 /* modifications for z */ 491 errno = 0; 492 _return_value = cmath_sinh_impl(module, z); 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 \ 516 {"sqrt", (PyCFunction)cmath_sqrt, METH_O, cmath_sqrt__doc__}, 517 518static Py_complex 519cmath_sqrt_impl(PyObject *module, Py_complex z); 520 521static PyObject * 522cmath_sqrt(PyObject *module, PyObject *arg) 523{ 524 PyObject *return_value = NULL; 525 Py_complex z; 526 Py_complex _return_value; 527 528 z = PyComplex_AsCComplex(arg); 529 if (PyErr_Occurred()) { 530 goto exit; 531 } 532 /* modifications for z */ 533 errno = 0; 534 _return_value = cmath_sqrt_impl(module, z); 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 \ 558 {"tan", (PyCFunction)cmath_tan, METH_O, cmath_tan__doc__}, 559 560static Py_complex 561cmath_tan_impl(PyObject *module, Py_complex z); 562 563static PyObject * 564cmath_tan(PyObject *module, PyObject *arg) 565{ 566 PyObject *return_value = NULL; 567 Py_complex z; 568 Py_complex _return_value; 569 570 z = PyComplex_AsCComplex(arg); 571 if (PyErr_Occurred()) { 572 goto exit; 573 } 574 /* modifications for z */ 575 errno = 0; 576 _return_value = cmath_tan_impl(module, z); 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 \ 600 {"tanh", (PyCFunction)cmath_tanh, METH_O, cmath_tanh__doc__}, 601 602static Py_complex 603cmath_tanh_impl(PyObject *module, Py_complex z); 604 605static PyObject * 606cmath_tanh(PyObject *module, PyObject *arg) 607{ 608 PyObject *return_value = NULL; 609 Py_complex z; 610 Py_complex _return_value; 611 612 z = PyComplex_AsCComplex(arg); 613 if (PyErr_Occurred()) { 614 goto exit; 615 } 616 /* modifications for z */ 617 errno = 0; 618 _return_value = cmath_tanh_impl(module, z); 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, z, base=<unrepresentable>, /)\n" 637"--\n" 638"\n" 639"log(z[, base]) -> the logarithm of z to the given base.\n" 640"\n" 641"If the base is not specified, returns the natural logarithm (base e) of z."); 642 643#define CMATH_LOG_METHODDEF \ 644 {"log", _PyCFunction_CAST(cmath_log), METH_FASTCALL, cmath_log__doc__}, 645 646static PyObject * 647cmath_log_impl(PyObject *module, Py_complex x, PyObject *y_obj); 648 649static PyObject * 650cmath_log(PyObject *module, PyObject *const *args, Py_ssize_t nargs) 651{ 652 PyObject *return_value = NULL; 653 Py_complex x; 654 PyObject *y_obj = NULL; 655 656 if (!_PyArg_CheckPositional("log", nargs, 1, 2)) { 657 goto exit; 658 } 659 x = PyComplex_AsCComplex(args[0]); 660 if (PyErr_Occurred()) { 661 goto exit; 662 } 663 if (nargs < 2) { 664 goto skip_optional; 665 } 666 y_obj = args[1]; 667skip_optional: 668 return_value = cmath_log_impl(module, x, y_obj); 669 670exit: 671 return return_value; 672} 673 674PyDoc_STRVAR(cmath_phase__doc__, 675"phase($module, z, /)\n" 676"--\n" 677"\n" 678"Return argument, also known as the phase angle, of a complex."); 679 680#define CMATH_PHASE_METHODDEF \ 681 {"phase", (PyCFunction)cmath_phase, METH_O, cmath_phase__doc__}, 682 683static PyObject * 684cmath_phase_impl(PyObject *module, Py_complex z); 685 686static PyObject * 687cmath_phase(PyObject *module, PyObject *arg) 688{ 689 PyObject *return_value = NULL; 690 Py_complex z; 691 692 z = PyComplex_AsCComplex(arg); 693 if (PyErr_Occurred()) { 694 goto exit; 695 } 696 return_value = cmath_phase_impl(module, z); 697 698exit: 699 return return_value; 700} 701 702PyDoc_STRVAR(cmath_polar__doc__, 703"polar($module, z, /)\n" 704"--\n" 705"\n" 706"Convert a complex from rectangular coordinates to polar coordinates.\n" 707"\n" 708"r is the distance from 0 and phi the phase angle."); 709 710#define CMATH_POLAR_METHODDEF \ 711 {"polar", (PyCFunction)cmath_polar, METH_O, cmath_polar__doc__}, 712 713static PyObject * 714cmath_polar_impl(PyObject *module, Py_complex z); 715 716static PyObject * 717cmath_polar(PyObject *module, PyObject *arg) 718{ 719 PyObject *return_value = NULL; 720 Py_complex z; 721 722 z = PyComplex_AsCComplex(arg); 723 if (PyErr_Occurred()) { 724 goto exit; 725 } 726 return_value = cmath_polar_impl(module, z); 727 728exit: 729 return return_value; 730} 731 732PyDoc_STRVAR(cmath_rect__doc__, 733"rect($module, r, phi, /)\n" 734"--\n" 735"\n" 736"Convert from polar coordinates to rectangular coordinates."); 737 738#define CMATH_RECT_METHODDEF \ 739 {"rect", _PyCFunction_CAST(cmath_rect), METH_FASTCALL, cmath_rect__doc__}, 740 741static PyObject * 742cmath_rect_impl(PyObject *module, double r, double phi); 743 744static PyObject * 745cmath_rect(PyObject *module, PyObject *const *args, Py_ssize_t nargs) 746{ 747 PyObject *return_value = NULL; 748 double r; 749 double phi; 750 751 if (!_PyArg_CheckPositional("rect", nargs, 2, 2)) { 752 goto exit; 753 } 754 if (PyFloat_CheckExact(args[0])) { 755 r = PyFloat_AS_DOUBLE(args[0]); 756 } 757 else 758 { 759 r = PyFloat_AsDouble(args[0]); 760 if (r == -1.0 && PyErr_Occurred()) { 761 goto exit; 762 } 763 } 764 if (PyFloat_CheckExact(args[1])) { 765 phi = PyFloat_AS_DOUBLE(args[1]); 766 } 767 else 768 { 769 phi = PyFloat_AsDouble(args[1]); 770 if (phi == -1.0 && PyErr_Occurred()) { 771 goto exit; 772 } 773 } 774 return_value = cmath_rect_impl(module, r, phi); 775 776exit: 777 return return_value; 778} 779 780PyDoc_STRVAR(cmath_isfinite__doc__, 781"isfinite($module, z, /)\n" 782"--\n" 783"\n" 784"Return True if both the real and imaginary parts of z are finite, else False."); 785 786#define CMATH_ISFINITE_METHODDEF \ 787 {"isfinite", (PyCFunction)cmath_isfinite, METH_O, cmath_isfinite__doc__}, 788 789static PyObject * 790cmath_isfinite_impl(PyObject *module, Py_complex z); 791 792static PyObject * 793cmath_isfinite(PyObject *module, PyObject *arg) 794{ 795 PyObject *return_value = NULL; 796 Py_complex z; 797 798 z = PyComplex_AsCComplex(arg); 799 if (PyErr_Occurred()) { 800 goto exit; 801 } 802 return_value = cmath_isfinite_impl(module, z); 803 804exit: 805 return return_value; 806} 807 808PyDoc_STRVAR(cmath_isnan__doc__, 809"isnan($module, z, /)\n" 810"--\n" 811"\n" 812"Checks if the real or imaginary part of z not a number (NaN)."); 813 814#define CMATH_ISNAN_METHODDEF \ 815 {"isnan", (PyCFunction)cmath_isnan, METH_O, cmath_isnan__doc__}, 816 817static PyObject * 818cmath_isnan_impl(PyObject *module, Py_complex z); 819 820static PyObject * 821cmath_isnan(PyObject *module, PyObject *arg) 822{ 823 PyObject *return_value = NULL; 824 Py_complex z; 825 826 z = PyComplex_AsCComplex(arg); 827 if (PyErr_Occurred()) { 828 goto exit; 829 } 830 return_value = cmath_isnan_impl(module, z); 831 832exit: 833 return return_value; 834} 835 836PyDoc_STRVAR(cmath_isinf__doc__, 837"isinf($module, z, /)\n" 838"--\n" 839"\n" 840"Checks if the real or imaginary part of z is infinite."); 841 842#define CMATH_ISINF_METHODDEF \ 843 {"isinf", (PyCFunction)cmath_isinf, METH_O, cmath_isinf__doc__}, 844 845static PyObject * 846cmath_isinf_impl(PyObject *module, Py_complex z); 847 848static PyObject * 849cmath_isinf(PyObject *module, PyObject *arg) 850{ 851 PyObject *return_value = NULL; 852 Py_complex z; 853 854 z = PyComplex_AsCComplex(arg); 855 if (PyErr_Occurred()) { 856 goto exit; 857 } 858 return_value = cmath_isinf_impl(module, z); 859 860exit: 861 return return_value; 862} 863 864PyDoc_STRVAR(cmath_isclose__doc__, 865"isclose($module, /, a, b, *, rel_tol=1e-09, abs_tol=0.0)\n" 866"--\n" 867"\n" 868"Determine whether two complex numbers are close in value.\n" 869"\n" 870" rel_tol\n" 871" maximum difference for being considered \"close\", relative to the\n" 872" magnitude of the input values\n" 873" abs_tol\n" 874" maximum difference for being considered \"close\", regardless of the\n" 875" magnitude of the input values\n" 876"\n" 877"Return True if a is close in value to b, and False otherwise.\n" 878"\n" 879"For the values to be considered close, the difference between them must be\n" 880"smaller than at least one of the tolerances.\n" 881"\n" 882"-inf, inf and NaN behave similarly to the IEEE 754 Standard. That is, NaN is\n" 883"not close to anything, even itself. inf and -inf are only close to themselves."); 884 885#define CMATH_ISCLOSE_METHODDEF \ 886 {"isclose", _PyCFunction_CAST(cmath_isclose), METH_FASTCALL|METH_KEYWORDS, cmath_isclose__doc__}, 887 888static int 889cmath_isclose_impl(PyObject *module, Py_complex a, Py_complex b, 890 double rel_tol, double abs_tol); 891 892static PyObject * 893cmath_isclose(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) 894{ 895 PyObject *return_value = NULL; 896 static const char * const _keywords[] = {"a", "b", "rel_tol", "abs_tol", NULL}; 897 static _PyArg_Parser _parser = {NULL, _keywords, "isclose", 0}; 898 PyObject *argsbuf[4]; 899 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; 900 Py_complex a; 901 Py_complex b; 902 double rel_tol = 1e-09; 903 double abs_tol = 0.0; 904 int _return_value; 905 906 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); 907 if (!args) { 908 goto exit; 909 } 910 a = PyComplex_AsCComplex(args[0]); 911 if (PyErr_Occurred()) { 912 goto exit; 913 } 914 b = PyComplex_AsCComplex(args[1]); 915 if (PyErr_Occurred()) { 916 goto exit; 917 } 918 if (!noptargs) { 919 goto skip_optional_kwonly; 920 } 921 if (args[2]) { 922 if (PyFloat_CheckExact(args[2])) { 923 rel_tol = PyFloat_AS_DOUBLE(args[2]); 924 } 925 else 926 { 927 rel_tol = PyFloat_AsDouble(args[2]); 928 if (rel_tol == -1.0 && PyErr_Occurred()) { 929 goto exit; 930 } 931 } 932 if (!--noptargs) { 933 goto skip_optional_kwonly; 934 } 935 } 936 if (PyFloat_CheckExact(args[3])) { 937 abs_tol = PyFloat_AS_DOUBLE(args[3]); 938 } 939 else 940 { 941 abs_tol = PyFloat_AsDouble(args[3]); 942 if (abs_tol == -1.0 && PyErr_Occurred()) { 943 goto exit; 944 } 945 } 946skip_optional_kwonly: 947 _return_value = cmath_isclose_impl(module, a, b, rel_tol, abs_tol); 948 if ((_return_value == -1) && PyErr_Occurred()) { 949 goto exit; 950 } 951 return_value = PyBool_FromLong((long)_return_value); 952 953exit: 954 return return_value; 955} 956/*[clinic end generated code: output=c6e3f37cd562c942 input=a9049054013a1b77]*/ 957