8000 gh-94906: Support multiple steps in math.nextafter by matthiasgoergens · Pull Request #103881 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-94906: Support multiple steps in math.nextafter #103881

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 23 commits into from
May 19, 2023
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
77fb4ae
pythongh-94906: Support multiple steps in math.nextafter
matthiasgoergens Apr 26, 2023
5e97978
Merge branch 'main' into gh-94906
matthiasgoergens May 2, 2023
0f2b30f
Merge remote-tracking branch 'origin/main' into gh-94906
matthiasgoergens May 17, 2023
b90e86c
Pass through NaN unchanged
matthiasgoergens May 17, 2023
accc22f
Explain that we need same endianness
matthiasgoergens May 17, 2023
8e1db39
Allow arbitrarily many steps
matthiasgoergens May 17, 2023
6873347
Fix problems
matthiasgoergens May 17, 2023
1fff8b4
Update regen-all
matthiasgoergens May 17, 2023
311f266
Make steps also available as a non-kw arg
matthiasgoergens May 17, 2023
cd70fea
Fix docs
matthiasgoergens May 17, 2023
e0421b6
Update docs
matthiasgoergens May 17, 2023
a8c83a7
Py_None instead of NULL
matthiasgoergens May 17, 2023
88c46c4
Fix typo
matthiasgoergens May 17, 2023
2232bb4
Tickle the CI/CD
matthiasgoergens May 17, 2023
a2724f6
Revert "Make steps also available as a non-kw arg"
matthiasgoergens May 17, 2023
b7b5ac6
Merge branch 'main' into gh-94906
matthiasgoergens May 17, 2023
b45f9c2
property based tests (should fail)
matthiasgoergens May 17, 2023
1f9d890
Property based tests
matthiasgoergens May 17, 2023
2153302
simplify
matthiasgoergens May 17, 2023
61c7c6e
Tickle CI/CD
matthiasgoergens May 17, 2023
04af22b
Merge branch 'main' into gh-94906
matthiasgoergens May 18 8000 , 2023
6527b77
Fix whitespace issue
mdickinson May 19, 2023
66ef3f9
Portability fix and a minor style fix
mdickinson May 19, 2023
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
Prev Previous commit
Portability fix and a minor style fix
  • Loading branch information
mdickinson committed May 19, 2023
commit 66ef3f968037c693fec059aa85f4740bf4ddf04f
28 changes: 19 additions & 9 deletions Modules/mathmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -3908,19 +3908,29 @@ math_nextafter_impl(PyObject *module, double x, double y, PyObject *steps)
return NULL;
}

uint64_t usteps = PyLong_AsUnsignedLongLong(steps);
unsigned long long usteps_ull = PyLong_AsUnsignedLongLong(steps);
// Conveniently, uint64_t and double have the same number of bits
// on all the platforms we care about.
// So if an overflow occurs, we can just use UINT64_MAX.
if (usteps == (unsigned long long)-1 && PyErr_Occurred()) {
if(!PyErr_ExceptionMatches(PyExc_OverflowError)) {
Py_DECREF(steps);
return NULL;
Py_DECREF(steps);
if (usteps_ull >= UINT64_MAX) {
// This branch includes the case where an error occurred, since
// (unsigned long long)(-1) = ULLONG_MAX >= UINT64_MAX. Note that
// usteps_ull can be strictly larger than UINT64_MAX on a machine
// where unsigned long long has width > 64 bits.
if (PyErr_Occurred()) {
if (PyErr_ExceptionMatches(PyExc_OverflowError)) {
PyErr_Clear();
}
else {
return NULL;
}
}
PyErr_Clear();
usteps = UINT64_MAX;
usteps_ull = UINT64_MAX;
}
Py_DECREF(steps);
assert(usteps_ull <= UINT64_MAX);
uint64_t usteps = (uint64_t)usteps_ull;

if (usteps == 0) {
return PyFloat_FromDouble(x);
}
Expand All @@ -3937,7 +3947,7 @@ math_nextafter_impl(PyObject *module, double x, double y, PyObject *steps)
// would be a "mixed-endian" double.)
union pun {double f; uint64_t i;};
union pun ux = {x}, uy = {y};
if(ux.i == uy.i) {
if (ux.i == uy.i) {
return PyFloat_FromDouble(x);
}

Expand Down
0