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
Let math.nextafter() compute multiple steps at a time. #94906
Comments
|
This feels like a needless expansion of the API to me; I don't think I've ever encountered a use-case for this. On the rare occasions that such a use-case turns up, what's wrong with the -1 from me. |
|
I wouldn't posted the issue if I hadn't needed this, so it is not "needless". In 30 seconds of searching, I found another example: Python is a high level language and it is suitable to incorporate options that are more expansive than used in low level languages like C that tend to focus on atomic steps. |
|
Sure, I don't doubt that you had a genuine need, but that need is trivially addressed with a Sorry, but I don't see this use-case as valuable enough or common enough to warrant expanding the I'm also concerned that this might be a performance trap: a user could easily write |
|
I concur with @mdickinson. It is too niche feature, and it is not difficult to implement a wrapper in Python. BTW, the case you found is in tests. |
|
I wish this wasn't dismissed so casually. All uses of nextafter() are "niche". There are only a handful of people who will ever use it. I submitted the feature request because I needed to write the replacement function in pure Python (much like the example I posted above) and it was distracting and felt amiss, like something the should have already have been built in to a higher level language. I wrote the function while working on another problem and had casually created an incorrect result along the way: Fortunately, I spotted the problem before going too far with it and wrote the above function giving the correct answer: The entire side trip was distracting and annoying. It took the focus away for the error analysis I was working on at the time. The proposal is an easy thing to do. It isn't even slightly confusing. It would be handy when needed by the few who ever use this function. I don't see any downside. Note, in numpy and scipy, most interesting functions have many options. That seems to work well for them. But in Python, there seems to be an urge to fight against the simplest of options as "unnecessary API expansion". |
|
@rhettinger @hauntsaninja @mdickinson You don't need a loop for this. See this pure Python prototype inspired by an old StackOverflow question of mine. And here's a prototype of a fix of the PR. (Please keep in mind that the C code in the PR isn't tested nor even run. The pure Python version has Hypothesis tests, so it's much more reliable.) |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

rhettinger commentedJul 16, 2022
Sometimes
math.nextafter()needs to be applied multiple times in succession.It would be nice if the function supported this directly:
The implementation would just be a for-loop:
The formal paramater can be just
nor the longer but more descriptivesteps.The text was updated successfully, but these errors were encountered: