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 and divrem with rounding argument #1955

Merged
merged 6 commits into from
Dec 3, 2024

Conversation

paemurru
Copy link
Contributor

@paemurru paemurru commented Nov 29, 2024

We add the standard Julia notation
div(5, 2, RoundUp)
also for the type ZZRingElem, so that we can write
div(ZZ(5), ZZ(2), RoundUp).

Also, we fix a bug. Namely, before there was the line:

Base.divrem(x::ZZRingElem, y::Int) = (Base.div(x, y), Base.rem(x, y))

But that is inefficient. The whole point of having a divrem function is to find the dividend and the remainder together. I have changed the above to

Base.divrem(x::ZZRingElem, y::Integer) = Base.divrem(x, ZZ(y))

We add the standard Julia notation
    `div(5, 2, RoundUp)`
also for the type `ZZRingElem`, so that we can write
    `div(ZZ(5), ZZ(2), RoundUp)`.
Fix previous bug: before, there was the line:

```
Base.divrem(x::ZZRingElem, y::Int) = (Base.div(x, y), Base.rem(x, y))
```

But that is inefficient. The whole point of having a `divrem` function
is to find the dividend and the remainder together. I have changed the
above to

```
Base.divrem(x::ZZRingElem, y::Integer) = Base.divrem(x, ZZ(y))
```
Copy link

codecov bot commented Nov 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.94%. Comparing base (2ead31a) to head (2c7268f).
Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1955      +/-   ##
==========================================
- Coverage   87.94%   87.94%   -0.01%     
==========================================
  Files          99       99              
  Lines       36416    36426      +10     
==========================================
+ Hits        32027    32034       +7     
- Misses       4389     4392       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@thofma
Copy link
Member

thofma commented Dec 2, 2024

@lgoettgens since you had a look at those recently, does this make sense? I think so, but it would be good for someone to confirm.

Copy link
Collaborator

@lgoettgens lgoettgens left a comment

Choose a reason for hiding this comment

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

Looks fine mathematically, thanks @paemurru! I just added some suggestions to condense all of the redirection/coercion dispatches with a rounding mode to not consider each and only rounding mode. I know that we don't support all of julias rounding modes, but it will still error once a "real working" function is reached, and it makes it easier to add more rounding modes. Besides that some small formatting suggestions to keep the style more consistent.
Before merging this, I think it would be great if you could add some simple tests that exercise all of these new functions. It doesn't need to be something elaborate or so, but maybe just one pair of inputs that differed between the different rounding modes, and then you input it in different data types and verify that the result is sane.

paemurru and others added 3 commits December 3, 2024 14:32
Co-authored-by: Lars Göttgens <lars.goettgens@gmail.com>
Co-authored-by: Lars Göttgens <lars.goettgens@gmail.com>
Copy link
Collaborator

@lgoettgens lgoettgens left a comment

Choose a reason for hiding this comment

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

Thanks, looks good from my POV. Let's wait for CI to finish

@fingolfin fingolfin merged commit 015e833 into Nemocas:master Dec 3, 2024
24 checks passed
@paemurru paemurru deleted the ep/add_div_with_rounding branch December 3, 2024 20:57
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