-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
Add math.ulp(x): unit in the last place #83491
Comments
In bpo-39288, I added math.nextafter(x, y) function. I propose to now add math.ulp() companion function. Examples from tests of my PR:
Unit in the last place:
In numpy, I found two references to ULP:
Attached PR implements math.ulp(x). |
See also math.isclose() and its PEP-485 which mentions ULP (Unit in the Last Place)... in the "Inappropriate uses" section :-)
Extract of an old python-ideas discussion on adding nextafter(): "It's also a little weird to jump from nextafter to isclose, since AFAIK https://mail.python.org/pipermail/python-ideas/2017-February/044832.html Other links: |
+1 |
Thank you Victor! Any chance you could look at fma too? bpo-29282 (The reward for a job well done is to be given more jobs :-) |
[Steven]
fma is hard, for reasons explained in the issue you linked to. If you have suggestions for resolving the difficulties, please do add them to that issue. |
Can I just say that "ulp" is totally non-obvious what that even means unless you have a specific math background? |
And sorry if that last response from me came off as grumpy; it wasn't meant to. I just had no clue what you were adding based on the name. |
The math.ulp() documentation explicitly says: https://docs.python.org/dev/library/math.html#math.ulp ULP stands for “Unit in the Last Place”. The term "ulp" is commonly used when talking about IEEE 754 floating point numbers. It is used in numpy and Java for example. test_math.py already had an ulp() function which was a pure Python implementation. The term is also commonly used in math articles. If you don't know the term "ulp", it's likely a *good thing*. You didn't have to suffer with rounding issues :-D |
I hear what you are saying, but "ulp" is the standard term of art. Sure Mathematics and numeric programming are rife with short names that are
to mention just a few. "ulp" is a technical, and subtle, concept to At least ulp is a TLA from English, unlike (say) "sine" which ultimately |
[Brett]
It's a good point. I guess we have a choice between using the domain-specific standard-ish name (which should be immediately meaningful to experts, but doesn't give much of a hint to non-experts) or using something more descriptive (which then risks confusing experts until they figure out "oh, that's just ulp"). There's also the option of spelling it out as "unit_in_last_place", but I'm not sure that benefits anyone. For meaningful descriptive names, "float_resolution" or "gap_to_next" are about the best I can come up with. "precision" is too ambiguous. NumPy has "numpy.spacing". But this exhibits exactly the trap of not using the "ulp" name: on a first glance, I incorrectly decided that NumPy didn't implement a ulp function. Then, having found If we can get people can coalesce around a preferred alternative name, we could consider changing this. |
In a different context, spelling out some variant of Hypertext_Transfer_Protocol would be as wrong-headed to avoid the "cryptic" http. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: