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
Scalars on units on right-hand of -> are silently ignored #305
Comments
Observed on numbat.dev as of 2024-01-30, FWIW |
Also, thanks for the lovely tool :-). It eases the pain on many day-to-day computations for me! |
Hi, can you expand a bit on what your expectations are? Is |
Hi! I would expect that one of three things would happen:
|
For me personally, I would expect Option 2 is interesting, as it's a way to define anonymous adhoc units. Today you'd have to do something like:
Edit: If we wanted to allow option 2, then maybe a more explicit syntax would be better: |
I have thought about this multiple times in the past. In my opinion, there are two approaches. The first approach is how Numbat currently behaves. The second is what you propose (if I understand correctly):
To illustrate this, imagine you want to know how many 45 min slots ( In approach (1), we have something like
In approach (2), we would probably print something like
unless I think there is an advantage here compared to just typing The other advantages are:
Just a curiosity: we can implement something similar to approach in Numbat already:
|
I think the use case for actually using scalars on the right is more obvious if you consider rate units. For example, On the other hand, rendering of the scalar might be confusing without a proper rational type in the units. For example, it wouldn’t be ideal to display the above example in 0.01 L/km. Is there any support for rationals at the moment? |
(Note that the above is what GNU Units does when producing output units.) |
That is a good example, yes!
Kind of the other way around. The current implementation treats It was easy to implement it like this and I kind of liked that both sides are simply expressions. No special parsing rules, no additional AST nodes, etc. And that implementation happened to fulfill this It has been increasingly clear to me that we want
Yes! I think with the feature proposed here, we could still fulfill the "convert to unit of variable" use case, if someone really needs that. We already have that mechanism to extract the unit of a quantity. And it would even look much clearer, because we would call And the new So let's implement this!
There is no support for rationals, but I'm thinking about it (#4 (comment)) |
Hi! If I write a scalar multiple on the right-hand side of a unit conversion, such as in
1 MB -> (B * 100)
, the100
seems to be silently ignored. See below:I would expect
1 MB -> B * 37
to be evaluated as(1 MB -> B) * 37
Apologies if this has already been reported; I wasn't able to find an existing issue
The text was updated successfully, but these errors were encountered: