-
Notifications
You must be signed in to change notification settings - Fork 22
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
Add as_raw_number(...)
utility
#333
Conversation
This lets us pave the way to change the behavior of quantity arithmetic when all units cancel out (#185). If we make this change all at once, it'll generally be too big and hard to handle. But if we provide this utility now, then people can migrate individual callsites gradually over time. Then, at the end (probably 0.5.0?), making the switch to the new behavior won't be such a big change. Helps #185.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds like this change will help migrate.
I feel like .in(unos)
isn't great if the quantity wasn't a unos
to begin with. But I do like keeping in the tradition of mentioning the type somewhere in the conversion statement. For example,
auto foo_p = percent(0.7);
...
double foo_d = foo_p.in(percent);
seems better than
auto foo_p = percent(0.7);
...
double foo_d = as_raw_number(foo_p);
@@ -534,6 +534,20 @@ constexpr auto operator%(Quantity<U1, R1> q1, Quantity<U2, R2> q2) { | |||
return make_quantity<U>(q1.in(U{}) % q2.in(U{})); | |||
} | |||
|
|||
// Callsite-readable way to convert a `Quantity` to a raw number. | |||
// | |||
// Only works for dimensionless `Quantities`; will return a compile-time error otherwise. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commend: Thanks for this clarification. I was worried about cases like as_raw_number(seconds(1))
.
Great analysis, and I agree. The main use case for using |
Oh! And just to be crystal-clear, |
This lets us pave the way to change the behavior of quantity arithmetic
when all units cancel out (#185). If we make this change all at once,
it'll generally be too big and hard to handle. But if we provide this
utility now, then people can migrate individual callsites gradually over
time. Then, at the end (probably 0.5.0?), making the switch to the new
behavior won't be such a big change.
Helps #185.