Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
gh-81313: Add the imath module#133909
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Conversation
This is a further development of#13741. |
A PEP is being written for this module:skirpichev/peps#8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
is this PR open (not draft) because there's an intent to merge it? (while a PEP is still being drafted?)
I left a comment on the PEP draft about naming (and conflict with an existing, maintained, Imath project)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Thanks, I'll link to this as an implementation.
.. function:: ilog2(n) | ||
Return the integer base 2 logarithm of the positive integer *n*. This is the | ||
floor of the exact base 2 logarithm root of *n*, or equivalently the | ||
greatest integer *k* such that | ||
2\ :sup:`k` |nbsp| ≤ |nbsp| *n* |nbsp| < |nbsp| 2\ :sup:`k+1`. | ||
It is equivalent to ``n.bit_length() - 1`` for positive *n*. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
This function seems redundant.
Also, I think it's better to first just plain moving of functions. No new features.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I'll remove it if you with.
Initially I planned to add more functions (in addition to new functionsisqrt()
,perm()
andcomb()
).ilog2()
is similar toint.bit_length()
, but uses__index__()
. After our discussion aboutmath.log()
I think that there is also a use case for 2-argumentilog()
(to determine the number of decimal digits in a number, for example). But this is a different issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
As any addition to the stdlib, I think it deserves at least own issue. Lets just settle up the new module and move things properly.
These functions accept integers and objects that implement the | ||
:meth:`~object.__index__` method which is used to convert the object to an integer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
In the same way we could simplify now description of argument processing in the math module. Except for a special snowflake "log" - all use PyFloat_AsDouble(). (Well, few functions also try special dunder methods.)
Though, probably it's for following prs.
I think that the PEP should be written before we handle this issue. |
|
Uh oh!
There was an error while loading.Please reload this page.
📚 Documentation preview 📚:https://cpython-previews--133909.org.readthedocs.build/