Skip to content

Conversation

@Adityazzzzz
Copy link

Fixes Issue #22170.

Changes:

  • Added abs() helper function to core.int128.
  • Added rem() (signed) and urem() (unsigned) wrapper functions.
  • Updated documentation for mul, div, and sar to clarify signed/unsigned behavior.
  • Added unit tests.

@dlang-bot
Copy link
Contributor

Thanks for your pull request and interest in making D better, @Adityazzzzz! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

⚠️⚠️⚠️ Warnings ⚠️⚠️⚠️

  • In preparation for migrating from Bugzilla to GitHub Issues, the issue reference syntax has changed. Please add the word "Bugzilla" to issue references. For example, Fix Bugzilla Issue 12345 or Fix Bugzilla 12345.(Reminder: the edit needs to be done in the Git commit message, not the GitHub pull request.)

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + dmd#22226"

@rikkimax
Copy link
Contributor

It would be good for a follow-up PR to add the overflow of signed/unsigned multiply that Iain mentioned in the ticket, if you are able to do so.

@Adityazzzzz
Copy link
Author

I have updated the changes in the PR, Please review

@Adityazzzzz
Copy link
Author

It would be good for a follow-up PR to add the overflow of signed/unsigned multiply that Iain mentioned in the ticket, if you are able to do so.

Sure! I will take a look at that in a separate PR once this is merged

* c1 = operand 1
* c2 = operand 2
* c1 = operand 1
* c2 = operand 2
Copy link
Contributor

Choose a reason for hiding this comment

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

More space removal.

* Params:
* c1 = dividend
* c2 = divisor
* c1 = dividend
Copy link
Contributor

Choose a reason for hiding this comment

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

More

* c1 = dividend
* c2 = divisor
* Returns:
* remainder c1 % c2
Copy link
Contributor

Choose a reason for hiding this comment

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

Indent.

* c1 = dividend
* c2 = divisor
* Returns:
* remainder c1 % c2
Copy link
Contributor

Choose a reason for hiding this comment

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

Again.

@Adityazzzzz
Copy link
Author

Done! I've implemented the changes.
Please review

// Test rem/urem
assert(rem(C10, C3) == C1); // 10 % 3 = 1
assert(urem(C10, C3) == C1);
assert(rem(Cm10, C3) == Cm1); // -10 % 3 = -1
Copy link
Member

@ibuclaw ibuclaw Dec 15, 2025

Choose a reason for hiding this comment

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

Perhaps add check that unsigned mod/remainder matches the % operator?

Suggested change
assert(rem(Cm10, C3) == Cm1); // -10 % 3 = -1
assert(rem(Cm10, C3) == Cm1); // -10 % 3 = -1
assert(urem(Cm10, C3) == C0); // -10U % 3 = 0

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.

4 participants