| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| :func:`math.atan2` and :func:`math.atan2pi` no longer raise :exc:`ValueError`. | ||
| :func:`cmath.phase` no longer raises :exc:`OverflowError` or :exc:`ValueError`, | ||
| and the values of ``math.atan2(b, a)`` and ``cmath.phase(complex(a, b))`` always | ||
| match. Contributed by High Performance Kernels LLC. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| The function :func:`math.copysign` no longer sets ``errno`` to zero. | ||
| Contributed by High Performance Kernels LLC. | ||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| Expand Up | @@ -1017,7 +1017,7 @@ math_1a(PyObject *arg, double (*func) (double), const char *err_msg) | |||||||
| The last rule is used to catch overflow on platforms which follow | ||||||||
| C89 but for which HUGE_VAL is not an infinity. | ||||||||
|
|
||||||||
| For most two-argument functions (copysign, fmod, hypot, atan2) | ||||||||
| For most two-argument functions (fmod, hypot) | ||||||||
|
Comment thread
Copy link
Copy Markdown
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityActually, the only remaining math_2()-type function is remainder()...
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityI think (fmod, hypot) in the comment above refers to the C math library functions.
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
I don't think so. Before 53876d9, both fmod and hypot were using FUNC2 macro.
Yes, but m_remainder (name in style m_log and co, suggesting a workarounded libm's function) is just an implementation of Annex F remainder. Perhaps, nowadays we could replace this function by standard library call: at least this works well for me locally. See previous attempt of removing legacy stuff: #101679 Edit: FYI, #158826.
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityInteresting. But it seems sufficiently unrelated as to allow this PR to be merged without further tweaks to the comments.
Sorry, something went wrong.
All reactions
|
||||||||
| these rules are enough to ensure that Python's functions behave as | ||||||||
| specified in 'Annex F' of the C99 standard, with the 'invalid' and | ||||||||
| 'divide-by-zero' floating-point exceptions mapping to Python's | ||||||||
| Expand All | @@ -1030,8 +1030,9 @@ math_2(PyObject *const *args, Py_ssize_t nargs, | |||||||
| double (*func) (double, double), const char *funcname) | ||||||||
| { | ||||||||
| double x, y, r; | ||||||||
| if (!_PyArg_CheckPositional(funcname, nargs, 2, 2)) | ||||||||
| if (!_PyArg_CheckPositional(funcname, nargs, 2, 2)) { | ||||||||
|
Comment thread
skirpichev marked this conversation as resolved.
|
||||||||
| return NULL; | ||||||||
| } | ||||||||
| x = PyFloat_AsDouble(args[0]); | ||||||||
| if (x == -1.0 && PyErr_Occurred()) { | ||||||||
| return NULL; | ||||||||
| Expand Down Expand Up | @@ -1060,6 +1061,29 @@ math_2(PyObject *const *args, Py_ssize_t nargs, | |||||||
| return PyFloat_FromDouble(r); | ||||||||
| } | ||||||||
|
|
||||||||
| /* variant of math_2, to be used when the function being wrapped is known NOT | ||||||||
| to need error checking (i.e., no overflow, invalid, or divide-by-zero). */ | ||||||||
|
Comment thread
Comment on lines
+1064
to
+1065
Copy link
Copy Markdown
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityI suggest expand this with atan2() example and remove other comments below.
Sorry, something went wrong.
All reactions
|
||||||||
|
|
||||||||
| static PyObject * | ||||||||
| math_2ne(PyObject *const *args, Py_ssize_t nargs, | ||||||||
| double (*func) (double, double), const char *funcname) | ||||||||
| { | ||||||||
| double x, y, r; | ||||||||
| if (!_PyArg_CheckPositional(funcname, nargs, 2, 2)) { | ||||||||
| return NULL; | ||||||||
|
Comment thread
picnixz marked this conversation as resolved.
|
||||||||
| } | ||||||||
| x = PyFloat_AsDouble(args[0]); | ||||||||
| if (x == -1.0 && PyErr_Occurred()) { | ||||||||
| return NULL; | ||||||||
| } | ||||||||
| y = PyFloat_AsDouble(args[1]); | ||||||||
| if (y == -1.0 && PyErr_Occurred()) { | ||||||||
| return NULL; | ||||||||
| } | ||||||||
| r = (*func)(x, y); // Ignore errno on purpose. | ||||||||
|
Comment thread
hpkfft marked this conversation as resolved.
Comment thread
Copy link
Copy Markdown
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
Suggested change
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality@vstinner asked for this comment on August 14: #153148 (comment)
Sorry, something went wrong.
All reactions
|
||||||||
| return PyFloat_FromDouble(r); | ||||||||
| } | ||||||||
|
|
||||||||
| #define FUNC1(funcname, func, can_overflow, docstring) \ | ||||||||
| static PyObject * math_##funcname(PyObject *self, PyObject *args) { \ | ||||||||
| return math_1(args, func, can_overflow, NULL); \ | ||||||||
| Expand Down Expand Up | @@ -1090,6 +1114,12 @@ math_2(PyObject *const *args, Py_ssize_t nargs, | |||||||
| }\ | ||||||||
| PyDoc_STRVAR(math_##funcname##_doc, docstring); | ||||||||
|
|
||||||||
| #define FUNC2NE(funcname, func, docstring) \ | ||||||||
| static PyObject * math_##funcname(PyObject *self, PyObject *const *args, Py_ssize_t nargs) { \ | ||||||||
| return math_2ne(args, nargs, func, #funcname); \ | ||||||||
| }\ | ||||||||
| PyDoc_STRVAR(math_##funcname##_doc, docstring); | ||||||||
|
|
||||||||
| FUNC1D(acos, acos, 0, | ||||||||
| "acos($module, x, /)\n--\n\n" | ||||||||
| "Return the arc cosine (measured in radians) of x.\n\n" | ||||||||
| Expand Down Expand Up | @@ -1121,11 +1151,14 @@ FUNC1(atan, atan, 0, | |||||||
| "atan($module, x, /)\n--\n\n" | ||||||||
| "Return the arc tangent (measured in radians) of x.\n\n" | ||||||||
| "The result is between -pi/2 and pi/2.") | ||||||||
| FUNC2(atan2, atan2, | ||||||||
| /* gh-153144: Ignore atan2 and atan2pi errno on purpose since it can optionally | ||||||||
|
Comment thread
hpkfft marked this conversation as resolved.
|
||||||||
| * be EDOM, which we should ignore, or ERANGE on underflow, which is | ||||||||
| * silent on Python. Overflow is not possible. */ | ||||||||
|
Comment thread
Comment on lines
+1154
to
+1156
Copy link
Copy Markdown
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
Suggested change
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality@vstinner asked for the "ignore errno on purpose" part of this comment on August 14: #153148 (comment)
Sorry, something went wrong.
All reactions
|
||||||||
| FUNC2NE(atan2, atan2, | ||||||||
| "atan2($module, y, x, /)\n--\n\n" | ||||||||
| "Return the arc tangent (measured in radians) of y/x.\n\n" | ||||||||
| "Unlike atan(y/x), the signs of both x and y are considered.") | ||||||||
| FUNC2(atan2pi, m_atan2pi, | ||||||||
| FUNC2NE(atan2pi, m_atan2pi, | ||||||||
| "atan2pi($module, y, x, /)\n--\n\n" | ||||||||
| "Return the arc tangent (measured in half-turns) of y/x.\n\n" | ||||||||
| "Unlike atanpi(y/x), the signs of both x and y are considered.") | ||||||||
| Expand Down Expand Up | @@ -1178,7 +1211,7 @@ math_ceil(PyObject *module, PyObject *number) | |||||||
| return PyLong_FromDouble(ceil(x)); | ||||||||
| } | ||||||||
|
|
||||||||
| FUNC2(copysign, copysign, | ||||||||
| FUNC2NE(copysign, copysign, | ||||||||
|
Comment thread
picnixz marked this conversation as resolved.
|
||||||||
| "copysign($module, x, y, /)\n--\n\n" | ||||||||
| "Return a float with the magnitude (absolute value) of x but the sign of y.\n\n" | ||||||||
| "On platforms that support signed zeros, copysign(1.0, -0.0)\n" | ||||||||
| Expand Down | ||||||||
| Back | FazBrowse Home | New Git URL |
Uh oh!
There was an error while loading. Please reload this page.