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

change promotion in rational conversion #49

Merged
merged 5 commits into from
Mar 10, 2023

Conversation

jishnub
Copy link
Contributor

@jishnub jishnub commented Feb 27, 2023

This lets one use an odd integer type as the numerator, which can't store 2. After this, one may use https://github.com/jishnub/OddEvenIntegers.jl to obtain

julia> Rational{Int}(half(Odd(1)))
1//2

This errors on master at present

@jishnub
Copy link
Contributor Author

jishnub commented Feb 27, 2023

Test failure seems unrelated

@sostock
Copy link
Owner

sostock commented Feb 27, 2023

Test failure seems unrelated

Yes, they are due to JuliaLang/julia#48735.

Copy link
Owner

@sostock sostock left a comment

Choose a reason for hiding this comment

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

Some comments:

  • There should be a test for this. I would just define a singleton type One <: Integer that represents the number 1, that way we don’t need to add OddEvenIntegers.jl as a test dependency.
  • This only fixes the behavior on Julia 1.5 and newer. On older Julia versions, the following method is used, which still calls oftype(tx, 2):
    (T::Type{<:Rational})(x::HalfInteger) = (tx=twice(x); T(tx,oftype(tx,2)))

    Since both HalfIntegers.jl and OddEvenIntegers.jl support Julia 1.0, I think we should change that method as well.
  • This change allows Rational{Int}(half(Odd(1))), but not Rational(half(Odd(1))). For that, the following line would need to be changed as well:
    Base.unsafe_rational(tx, oftype(tx, 2))

src/HalfIntegers.jl Outdated Show resolved Hide resolved
Co-authored-by: Sebastian Stock <42280794+sostock@users.noreply.github.com>
@codecov-commenter
Copy link

codecov-commenter commented Feb 28, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change

Comparison is base (215556a) 99.20% compared to head (228551f) 99.20%.

❗ Current head 228551f differs from pull request most recent head 20d5b73. Consider uploading reports for the commit 20d5b73 to get more accurate results

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@           Coverage Diff           @@
##           master      #49   +/-   ##
=======================================
  Coverage   99.20%   99.20%           
=======================================
  Files           1        1           
  Lines         250      250           
=======================================
  Hits          248      248           
  Misses          2        2           
Impacted Files Coverage Δ
src/HalfIntegers.jl 99.20% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@jishnub
Copy link
Contributor Author

jishnub commented Mar 6, 2023

@sostock I've added tests and implemented the changes as suggested

test/customtypes.jl Outdated Show resolved Hide resolved
Co-authored-by: Sebastian Stock <42280794+sostock@users.noreply.github.com>
@jishnub
Copy link
Contributor Author

jishnub commented Mar 10, 2023

Gentle bump

@sostock sostock merged commit 82a8348 into sostock:master Mar 10, 2023
@jishnub jishnub deleted the rationalpromote branch March 10, 2023 12:28
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.

3 participants