Skip to content

gh-53032: support IEEE 754 contexts in the decimal module #122003

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 15 commits into from
Apr 28, 2025

Conversation

skirpichev
Copy link
Member

@skirpichev skirpichev commented Jul 19, 2024

This was in C version from beginning, but available only on conditional compilation (EXTRA_FUNCTIONALITY). Current patch adds function to create IEEE contexts to the pure-python module as well.


Notes for reviewers:

  • this doesn't expose integer constants like DECIMAL32 (which is, surprise, 32)
  • doesn't change function name (I would prefer something like ieee_context() instead)
  • doesn't change error handling. But, perhaps, a ValueError (with same message in all cases) is better than OverflowError if bits>sys.maxsize?

This was in C version from beginning, but available only
on conditional compilation (EXTRA_FUNCTIONALITY).  Current
patch adds function to create IEEE contexts to the
pure-python module as well.
@skirpichev skirpichev force-pushed the expose-ieee_context-53032 branch from 1be7598 to b833af8 Compare July 19, 2024 04:42
@skirpichev skirpichev marked this pull request as ready for review July 19, 2024 05:09
@skirpichev skirpichev requested a review from rhettinger as a code owner July 19, 2024 05:09
@rhettinger
Copy link
Contributor

@tim-one Any thoughts on this? Do anyone need it? Does the name make send? Do we want to go beyond what is in the decimal spec?

I'm neutral on this. It seems both harmless and gratuitous.

@skirpichev
Copy link
Member Author

skirpichev commented Jul 21, 2024

I would expect that any advocacy (or critique) of the feature - belongs rather to the issue thread, not to implementation. BTW, since C23 - these types are part of the C standard.

I should emphasize that even if this will be rejected - there is a bug in main, that should be fixed. See #122081.

Copy link
Member

@tim-one tim-one left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No material comments from me - it's simple, and looks good!

@skirpichev
Copy link
Member Author

CC @vstinner

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
@picnixz
Copy link
Member

picnixz commented Jan 24, 2025

For the docs failures: you just need to merge main since we fixed blurb

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a new feature, it needs a What's New entry and the versionadded directive.

I do not know why it was optional and not enabled by default, whether it is correct and what is a use for this feature.

cc @skrah, @mdickinson, @tim-one, @rhettinger

Copy link
Member

@picnixz picnixz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm leaving in a few minutes for 2 weeks roughly so just one nit. I haven't looked at the formulation and grammar so a native speaker could check before the merge or we can amend it later if needs arise. Ottherwise I'm happy that we didn't remove the constants even though they could be useless most of the time.

So, if the tests were only moved around and expanded and not reduced, I think this can be merged.

As for why it hasn't been exposed first I think it may have been because it's experimental/wasn't deemed useful at that time maybe?

@skirpichev
Copy link
Member Author

I'm happy that we didn't remove the constants even though they could be useless most of the time.

I'm worry we only delay the decision to do this.

@picnixz
Copy link
Member

picnixz commented Jan 27, 2025

We can deprecate it in a follow-up PR. I just wanted to have the changes documented and notified.

@vstinner
Copy link
Member

@serhiy-storchaka: So what do you think of this change? Does it look good to you?

@skirpichev
Copy link
Member Author

What's New entry and the versionadded directive.

done

I do not know why it was optional and not enabled by default, whether it is correct and what is a use for this feature.

It was added to the mpdecimal a long time ago, so I would expect it's correct.

See the issue thread for use cases. BTW, this feature was added in 1919b7e. I would guess it was wrapped under EXTRA_FUNCTIONALITY just because the pure-Python version missed this stuff.

@skirpichev
Copy link
Member Author

CC @vstinner

what is a use for this feature.

@serhiy-storchaka, as Mark said in the issue description - that's to simplify communication with libraries, that understand the IEEE 754 (2008) decimal interchange formats. (This is now a part of C23 as Annex H).

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not a IEEE decimals expert, but technically the code LGTM.

@vstinner vstinner merged commit 5bf0f36 into python:main Apr 28, 2025
42 checks passed
@vstinner
Copy link
Member

Merged, congrats @skirpichev!

@skirpichev skirpichev deleted the expose-ieee_context-53032 branch April 28, 2025 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants