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

Add div family methods (div, cld, fld, rem, mod) #16

Merged
merged 6 commits into from
May 28, 2024
Merged

Add div family methods (div, cld, fld, rem, mod) #16

merged 6 commits into from
May 28, 2024

Conversation

BioTurboNick
Copy link
Collaborator

@BioTurboNick BioTurboNick commented May 27, 2024

This PR adds the div family methods (div, cld, fld, rem, mod) and operators (÷, %) to the set.

Since integer division is so slow (see #9), we can afford branches to avoid undefined behavior produced by just using the intrinsic directly. Could consider an unsafe mode, but unclear benefits from that at this stage.

For unchecked methods, we're defining divide-by-zero to produce zero, and typemin() ÷ -1 to overflow to typemin(Int).

For saturating methods, we're defining divide-by-zero to produce typemin(), zero() or typemax() based on the sign of the dividend, and typemin() ÷ -1 produces typemax().

Base.divrem isn't present at the moment because Base.Checked doesn't have a checked_divrem method. Also, Base has a complicated infrastructure for rounding modes that isn't implemented here because Base.Checked doesn't either.

@BioTurboNick
Copy link
Collaborator Author

Tests still need to be made more complete.

@BioTurboNick
Copy link
Collaborator Author

Since this substantially changes the behavior of what happens inside the macros, this will also be 0.3.

@BioTurboNick BioTurboNick merged commit 28b3b6a into main May 28, 2024
12 checks passed
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.

1 participant