Skip to content

Fix rem of a Rational into a Normed type - #349

Merged
kimikage merged 3 commits into
JuliaMath:masterfrom
PatrickHaecker:rational-rem
Oct 10, 2026
Merged

kimikage merged 3 commits into
JuliaMath:masterfrom
PatrickHaecker:rational-rem

Conversation

@PatrickHaecker

Copy link
Copy Markdown
Collaborator

(1//3) % N0f8 threw a MethodError, because _unsafe_trunc fell back to unsafe_trunc, which had no Rational method.

`(1//3) % N0f8` threw a `MethodError`, because `_unsafe_trunc` fell back
to `unsafe_trunc`, which had no `Rational` method.
@codecov

codecov Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.84%. Comparing base (b863f66) to head (c5bfe2d).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #349   +/-   ##
=======================================
  Coverage   96.83%   96.84%           
=======================================
  Files           7        7           
  Lines         791      793    +2     
=======================================
+ Hits          766      768    +2     
  Misses         25       25           

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kimikage kimikage left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Good catch.

In actual cases, the denominator should always be 1, but I don't think that is a major issue.

Although it is not the focus of this PR, I think it would be good to have tests for Fixed as well, for the sake of the future.

Comment thread test/normed.jl Outdated
Comment thread test/normed.jl Outdated
@PatrickHaecker

Copy link
Copy Markdown
Collaborator Author

In actual cases, the denominator should always be 1, but I don't think that is a major issue.

Oh, indeed. _rem rounds first, so the Rational is always integral there. However, I just checked: The compiler already drops the division. So I kept the version that is correct for any Rational – more generic with same speed (but by luck, so thanks for pointing it out).

Although it is not the focus of this PR, I think it would be good to have tests for Fixed as well, for the sake of the future.

  • I have added the same kind of tests for Q0f7.

Comment thread test/fixed.jl Outdated
`Q0f7(1/3)` states the intent better than `Q0f7(43 / 128)` and is still an
independent reference, because the constructor rounds in `_convert`, not in `_rem`.
@kimikage
kimikage merged commit 8d2daab into JuliaMath:master Oct 10, 2026
13 checks passed
@kimikage

Copy link
Copy Markdown
Collaborator

Thank you for your contribution.

@PatrickHaecker
PatrickHaecker deleted the rational-rem branch October 11, 2026 01:35
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