Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Update math error messages for 3.14 (2) #18949

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

Merged
merged 1 commit into from
Apr 22, 2025
Merged
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
21 changes: 21 additions & 0 deletions 21 mypyc/lib-rt/float_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ static double CPy_MathExpectedPositiveInputError(double x) {
return CPY_FLOAT_ERROR;
}

static double CPy_MathExpectedFiniteInput(double x) {
char *buf = PyOS_double_to_string(x, 'r', 0, Py_DTSF_ADD_DOT_0, NULL);
if (buf) {
PyErr_Format(PyExc_ValueError, "expected a finite input, got %s", buf);
PyMem_Free(buf);
}
return CPY_FLOAT_ERROR;
}

double CPyFloat_FromTagged(CPyTagged x) {
if (CPyTagged_CheckShort(x)) {
return CPyTagged_ShortAsSsize_t(x);
Expand All @@ -48,22 +57,34 @@ double CPyFloat_FromTagged(CPyTagged x) {
double CPyFloat_Sin(double x) {
double v = sin(x);
if (unlikely(isnan(v)) && !isnan(x)) {
#if CPY_3_14_FEATURES
return CPy_MathExpectedFiniteInput(x);
#else
return CPy_DomainError();
#endif
}
return v;
}

double CPyFloat_Cos(double x) {
double v = cos(x);
if (unlikely(isnan(v)) && !isnan(x)) {
#if CPY_3_14_FEATURES
return CPy_MathExpectedFiniteInput(x);
#else
return CPy_DomainError();
#endif
}
return v;
}

double CPyFloat_Tan(double x) {
if (unlikely(isinf(x))) {
#if CPY_3_14_FEATURES
return CPy_MathExpectedFiniteInput(x);
#else
return CPy_DomainError();
#endif
}
return tan(x);
}
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.