-
Notifications
You must be signed in to change notification settings - Fork 117
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
base: master
Are you sure you want to change the base?
Conversation
0a748c7
to
7acdd66
Compare
Codecov Report
📣 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
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
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. |
Equality with zero is already convenient and perfectly general in Julia: As |
I agree that it's convenient. I just worry about general consistency. You'd have that |
Sorry, that's just an oversight! Can easily add |
Yeah, but then you'd have that x less-than-or-equal y is not the same as |
Some previous discussion: #455 Another point to consider: it feels inconsistent to me that But it would be nice to have a more convenient method of comparing with zero. |
There is also the philosophical question, raised in this book, that one can easily define negative units, so any sort of ordering operation like using Unitful
@unit negajoule "nJ" negajoule -1u"J" false
2u"J" > 0u"J" # true
2u"negajoule" > 0u"negajoule" # true
2u"J" > 0 # ????
2u"negajoule" > 0 # ??? This is perhaps a philosophical nitpick more than a "practical" one, since in this example we do have the following odd result as well: 2u"J" > 2u"negajoule" # true... But there is nothing "special" about any particular unit scale, particularly when it comes to things like energy that can only be defined with respect to some reasonable reference standard (and could therefore just as easily have an opposite sign). |
My point in this PR was purely pragmatical: if I want to check if a length or whatever other quantity is greater than zero, it doesn't matter what units this zero has. Currently, one needs to write |
Or Rereading the issue now, I wondered if it would it have impact on inference / code-gen? We'd go from All in all, while it's a very nice idea, feels like the complications outweigh the benefit/convenience. |
Can only use it in a package if it already depends on Unitful – not in generic code. |
This is convenient and unambiguous when constrained for scalar units