8000 gh-81313: Add the imath module by serhiy-storchaka · Pull Request #133909 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

serhiy-storchaka
Copy link
Member
@serhiy-storchaka serhiy-storchaka commented May 11, 2025

@serhiy-storchaka
Copy link
Member Author

This is a further development of #13741.

@vstinner
Copy link
Member

A PEP is being written for this module: skirpichev/peps#8

@vstinner
Copy link
Member

cc @skirpichev

Copy link
Contributor
@itamaro itamaro left a 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)

Copy link
Member
@skirpichev skirpichev left a 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.

Comment on lines +52 to +59
.. 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*.
Copy link
Member

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.

Copy link
Member Author

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 functions isqrt(), perm() and comb()). ilog2() is similar to int.bit_length(), but uses __index__(). After our discussion about math.log() I think that there is also a use case for 2-argument ilog() (to determine the number of decimal digits in a number, for example). But this is a different issue.

Copy link
Member

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.

Comment on lines +12 to +13
These functions accept integers and objects that implement the
:meth:`~object.__index__` method which is used to convert the object to an integer
Copy link
Member

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.

@corona10
Copy link
Member

I think that the PEP should be written before we handle this issue.

@skirpichev
Copy link
Member

I think that the PEP should be written before we handle this issue.

python/peps#4422

@skirpichev skirpichev self-requested a review May 13, 2025 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0