-
Notifications
You must be signed in to change notification settings - Fork 79
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
Odd behavior when taking a square root #474
Comments
I would expect to see this if you're doing a unit conversion between two units whose ratio has a rational power. The reason is that we always compute unit conversion factors at compile time, but we can't currently compute rational powers at compile time. What we'd need is a In any case, the code you've written is perfectly valid for the future version of this library which includes this feature. 🙂 In the meantime, I thought it would be better to produce a hard error rather than return an approximate (i.e., incorrect) result. The reason you're able to get it to work is that when you do the conversion in squared speed, rather than speed, the conversion factor doesn't have any rational powers. |
Nearly all I also refactored your example a bit here: https://godbolt.org/z/v6Tf8o3hT. |
Can we take advantage of that yet, though, and still maintain the C++20 compatibliity? WDYT --- will we need to detect |
or do |
In theory you should still have to take a square root of one to get another conversion factor. I take it there is some constexpr check for that.
I get the feeling, but taking a sqrt of something is too common to leave as "just wait until you have a C++23 compiler." That laves any volume/area conversion to a length as impossible let alone my energy to velocity conversions. I'll try to put together an option dependency to gcem. Is it safe to say that only that place in compute_base_power needs to be changed? |
There are two things going on here: a unit conversion, and a runtime square root computation. The reason it works when you do the unit conversion between the squared quantities is that you're essentially pushing all of the square-root-ness into the runtime computation.
Yes, I expect that is the only place that would need to be changed. |
I'm not expecting to be able to work on this before March at the earliest, because any spare bandwidth I might have would go towards the standard units library papers instead. That said, I do have some good news: Au has now implemented this feature! See aurora-opensource/au#213. The strategy I used was to write a Even though I don't have time to work on this for mp-units for the next several months, I'm still posting this here so that folks can discuss the implementation strategy if they want. Then it'll be just a matter of finding time to implement this. |
I'm playing around with this library, and I found some odd behavior
This is to calculate the average speed of a particle in a Maxwellian distribution.
I wrote something simple to do this
This currently fails to compile with at magnitude.h line 310
I think its trying to take a square root of a boltzmann constant which is not allowed. The type of Internal seem measured in K * k_b / Da.
However, if I replace the return statement of my AverageSpeed function with
then everything compiles. Is there a good argument for why the value_cast in necessary here?
The text was updated successfully, but these errors were encountered: