Skip to content
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

[6.1][stdlib] Fix recoverable [U]Int128 division-by-zero #78045

Conversation

oscbyspro
Copy link
Contributor

@oscbyspro oscbyspro commented Dec 7, 2024

  • Explanation: Int128 and UInt128 division by zero did not behave like smaller binary integer division by zero. This contribution updates the various division operations accordingly. It adds a missing precondition in signed %(_:_:) and replaces the preconditions in *ReportingOverflow with recoverable results consistent with documented behavior.
  • Scope: Updates Int128 and UInt128 division methods.
  • Issues: 128-bit core binary integer support oscbyspro/Ultimathnum#143
  • Original PRs: Fix recoverable [U]Int128 division-by-zero #77854
  • Risk: It updates some arithmetic functions of relatively new types.
  • Testing: Adding corresponding 128-bit division unit tests would be prudent.
  • Reviewers: @stephentyrone (approved) @xwu (commented)

This patch fixes the division-by-zero case in the following methods:

- `Int128/dividedReportingOverflow(by:)`
- `Int128/remainderReportingOverflow(dividingBy:)`
- `UInt128/dividedReportingOverflow(by:)`
- `UInt128/remainderReportingOverflow(dividingBy:)`
Jumping on the `_slowPath(_:)` bandwagon like all other integer types.
I have paraphrased @stephentyrone's and @xwu's review comments to the best of my ability.
@oscbyspro oscbyspro requested a review from a team as a code owner December 7, 2024 18:47
@stephentyrone
Copy link
Contributor

@swift-ci test

@stephentyrone stephentyrone merged commit 332b24a into swiftlang:release/6.1 Dec 8, 2024
5 checks passed
@stephentyrone
Copy link
Contributor

Thanks @oscbyspro!

@oscbyspro oscbyspro deleted the fixes/128-bit-division-by-zero-6.1 branch December 8, 2024 08:13
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.

2 participants