-
Notifications
You must be signed in to change notification settings - Fork 94
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
Converting between time and frequency is difficult #670
Comments
You can't (directly) convert a time in femtoseconds to a frequency in hertz, because a time is not a frequency. What you're looking for is a smart inverse function, i.e., ...of course, since |
Of course, an alternative way to get the correct answer would be to use an explicit-rep variant of |
@chiphogg, I never thought about adding such an overload for inverse. It might be a good idea, though. |
Yeah, it's similar to that table we made of all the different ways to spell Anyway... adding an API option like this is just part of that same grammar that we were expanding on in that table. We need to find some way to give users a way to tell us which rep to use. Oh, and we probably also need to add that hard compiler error for the implicit rep case on inputs like these too. 😅 |
Do you mean this table: https://mpusz.github.io/mp-units/latest/users_guide/framework_basics/value_conversions/#value-conversions-summary?
Probably yes. Could you please file an issue for this? |
That looks like a distilled version of the table I had in mind. I did end up tracking down the original. I remembered the original being much bigger, and it is --- but I think that boils down to not including a column for quantity spec on the official doc page. (I think the new table is equivalent to the old table if we keep only rows where I filed #671 to track the hard compiler error. |
This is listed as completed in 5d4e1aa, but I don't see any new (I'm reopening for bookkeeping because I'm reasonably confident the linked commit doesn't solve the problem, but if I'm wrong about that, it'll be easy enough to close this issue again.) |
The current code with I am unsure if we should provide additional overloads for each function that can change the unit. |
If this is the same thing as the hard compiler error, then why did you ask me to file #671 as a separate issue? 😅 The interfaces are subtly different in principle. Now, in this specific case, I don't think the two options are meaningfully different in practice. For
If you can think of a combination of quantities and types where these are meaningfully different, then we should consider adding the explicit-rep overloads. If we can't, then it's probably fine to just close this ticket again. But the distinction between the explicit-rep version, and an explicit conversion of the inputs, remains important in general, and we should be asking ourselves these questions for every interface IMO. |
I didn't want to track the overflowing conversion issue here as this issue was clearly about the user's misunderstanding of time and frequency quantities (there is no way to convert between those). This is why I planned to close it after your explanation, leaving the other one open. |
Sure. However, I do not want to explode the overload sets without a very good reason. It would make it harder to standardize. We can always add more overloads if needed, even in the following C++ releases. I would prefer to see compelling use cases from our users first, though. It would make it easier for us to defend additional overloads in the Committee. |
Makes sense, thanks! |
Given this example I would expect a conversion from femtoseconds to hertz, currently this is a compilation error. Is this intended behaviour? Edit: this is possible by dividing
1.0
byf
, which works but doesnt work on embedded devices without floating point.The text was updated successfully, but these errors were encountered: