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

Disallow StepRange{<:Quantity{<:AbstractFloat}} #560

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

sostock
Copy link
Collaborator

@sostock sostock commented Sep 14, 2022

For unitless numbers, StepRange enforces certain restrictions:

julia> StepRange(1.0, 2.0, 3.0)
ERROR: ArgumentError: StepRange should not be used with floating point
[...]

julia> StepRange(1, 1//2, 2)
ERROR: ArgumentError: StepRange{<:Integer} cannot have non-integer step
[...]

However, for unitful quantities, these are currently allowed:

julia> StepRange(1.0u"m", 2.0u"m", 3.0u"m")
(1.0:2.0:3.0) m

julia> StepRange(1u"m", (1//2)u"m", 2u"m")
(1//1:1//2:2//1) m

julia> ans[2]
ERROR: InexactError: Int64(3//2)
[...]

After this PR, the restrictions that apply to unitless numbers are also applied to unitful quantities. Closes #552.

Edit: We would have to drop support for Julia < 1.6 for this PR. I checked that it works with Julia 1.6 and 1.7.

@codecov-commenter
Copy link

codecov-commenter commented Sep 14, 2022

Codecov Report

Merging #560 (e2e8fa9) into master (634071e) will decrease coverage by 0.41%.
The diff coverage is 77.77%.

@@            Coverage Diff             @@
##           master     #560      +/-   ##
==========================================
- Coverage   87.93%   87.51%   -0.42%     
==========================================
  Files          16       16              
  Lines        1450     1450              
==========================================
- Hits         1275     1269       -6     
- Misses        175      181       +6     
Impacted Files Coverage Δ
src/range.jl 90.10% <77.77%> (-1.46%) ⬇️
src/Unitful.jl 83.33% <0.00%> (-16.67%) ⬇️
src/quantities.jl 92.88% <0.00%> (-1.26%) ⬇️
src/units.jl 84.00% <0.00%> (-0.67%) ⬇️
src/user.jl 95.60% <0.00%> (+0.34%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@sostock sostock added the v2.0 label Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

StepRange with float-based quantities should error
2 participants