Thanks to visit codestin.com
Credit goes to github.com

Skip to content

gh-133895: correct values of cmath.cosh/sinh in case of overflows #135603

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions Modules/clinic/cmathmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 10 additions & 8 deletions Modules/cmathmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,9 @@ cmath_cosh_impl(PyObject *module, Py_complex z)
x_minus_one = z.real - copysign(1., z.real);
r.real = cos(z.imag) * cosh(x_minus_one) * Py_MATH_E;
r.imag = sin(z.imag) * sinh(x_minus_one) * Py_MATH_E;
if (isnan(r.imag)) {
r.imag = copysign(0., z.real*z.imag);
}
} else {
r.real = cos(z.imag) * cosh(z.real);
r.imag = sin(z.imag) * sinh(z.real);
Expand Down Expand Up @@ -674,6 +677,9 @@ cmath_sinh_impl(PyObject *module, Py_complex z)
x_minus_one = z.real - copysign(1., z.real);
r.real = cos(z.imag) * sinh(x_minus_one) * Py_MATH_E;
r.imag = sin(z.imag) * cosh(x_minus_one) * Py_MATH_E;
if (isnan(r.imag)) {
r.imag = copysign(0., z.imag);
}
} else {
r.real = cos(z.imag) * sinh(z.real);
r.imag = sin(z.imag) * cosh(z.real);
Expand Down Expand Up @@ -972,7 +978,7 @@ cmath_polar_impl(PyObject *module, Py_complex z)
static Py_complex rect_special_values[7][7];

/*[clinic input]
cmath.rect
cmath.rect -> Py_complex_protected

r: double
phi: double
Expand All @@ -981,9 +987,9 @@ cmath.rect
Convert from polar coordinates to rectangular coordinates.
[clinic start generated code]*/

static PyObject *
static Py_complex
cmath_rect_impl(PyObject *module, double r, double phi)
/*[clinic end generated code: output=385a0690925df2d5 input=24c5646d147efd69]*/
/*[clinic end generated code: output=74ff3d17585f3388 input=50e60c5d28c834e6]*/
{
Py_complex z;
errno = 0;
Expand Down Expand Up @@ -1027,11 +1033,7 @@ cmath_rect_impl(PyObject *module, double r, double phi)
z.imag = r * sin(phi);
errno = 0;
}

if (errno != 0)
return math_error();
else
return PyComplex_FromCComplex(z);
return z;
}

/*[clinic input]
Expand Down
Loading