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

support comparison with zero #640

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

aplavin
Copy link
Contributor

@aplavin aplavin commented Mar 31, 2023

This is convenient and unambiguous when constrained for scalar units

@aplavin aplavin force-pushed the patch-1 branch 3 times, most recently from 0a748c7 to 7acdd66 Compare March 31, 2023 22:19
@codecov-commenter
Copy link

codecov-commenter commented Mar 31, 2023

Codecov Report

Merging #640 (80feacf) into master (49623e0) will decrease coverage by 0.05%.
The diff coverage is 66.66%.

❗ Current head 80feacf differs from pull request most recent head be53711. Consider uploading reports for the commit be53711 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

@@            Coverage Diff             @@
##           master     #640      +/-   ##
==========================================
- Coverage   89.06%   89.02%   -0.05%     
==========================================
  Files          16       16              
  Lines        1491     1494       +3     
==========================================
+ Hits         1328     1330       +2     
- Misses        163      164       +1     
Impacted Files Coverage Δ
src/quantities.jl 93.97% <66.66%> (-0.34%) ⬇️

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

@cstjean
Copy link
Contributor

cstjean commented Mar 31, 2023

By the same token, you could support addition by 0 and equality with 0. But unfortunately,

julia> 0u"m" == 0
false

so that'd be a breaking change.

@aplavin
Copy link
Contributor Author

aplavin commented Mar 31, 2023

Equality with zero is already convenient and perfectly general in Julia: iszero(some_unitful_function()). It doesn't require any further operators, especially breaking.

As isless is bound with isequal according to their docstring, I agree that isless shouldn't be defined here. Can remove it, thanks for pointing out!
But there's no restriction on <, and being able to do some_unitful_function() > 0 would be an improvement.

@cstjean
Copy link
Contributor

cstjean commented Apr 1, 2023

But there's no restriction on <, and being able to do some_unitful_function() > 0 would be an improvement.

I agree that it's convenient. I just worry about general consistency. You'd have that 0m < 0, 0m > 0, 0m == 0 all false. 0 <= 0m would also be false, which is particularly uncomfortable.

@aplavin
Copy link
Contributor Author

aplavin commented Apr 1, 2023

0 <= 0m would also be false

Sorry, that's just an oversight! Can easily add <= as well. It's also non-breaking, same as <.

@cstjean
Copy link
Contributor

cstjean commented Apr 1, 2023

Yeah, but then you'd have that x less-than-or-equal y is not the same as x<y || x==y

@sostock
Copy link
Collaborator

sostock commented Apr 13, 2023

Some previous discussion: #455

Another point to consider: it feels inconsistent to me that 0 < 1m holds, but 0s < 1m doesn’t.

But it would be nice to have a more convenient method of comparing with zero.

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