Hello,
<obligatory appreciation on first post>
I started using Boost just for boost::units and I find new ways boost can
help me almost every day. So thanks for the great stuff!
My question to the board is why two absolute quantities (si::temperature (K)
in my case) can't be summed in boost::units?
I realized that this is a rule enforced by-design
(gmane.comp.lib.boost.user/71747), and I understand that it is probably not
a very common case, but I wanted my code to solve a simple formula which
requires adding up two absolute temperatures
(quantity
AMDG On 12/30/2015 05:49 AM, Itzik wrote:
Eventually it turned out that I was mistaken with the formula, and subtraction was required instead, so there's no problem there. Alas, there's also a much simpler use case: What if I want to average the temperature of the last N readouts? Shouldn't boost::units support this simple operation?
There's actually an alternate formula that does work: M = 0 For i = 1..N M += (X_i - M)/i The normal M = \sum X_i / N fails because of two operators, + and /, not just +. If you support that, I'm not sure what the point of using absolute in the first place is.
I have no formal physics education, but intuitively, adding two absolute temperatures doesn't seem really like a mistake to me, even if it's an odd thing to do.
In the case of the average, the addition gives an intermediate result which has no meaning by itself. This is forbidden by design. If this isn't what you need, don't use absolute. In Christ, Steven Watanabe
Steven Watanabe wrote:
AMDG
On 12/30/2015 05:49 AM, Itzik wrote:
Eventually it turned out that I was mistaken with the formula, and subtraction was required instead, so there's no problem there. Alas, there's also a much simpler use case: What if I want to average the temperature of the last N readouts? Shouldn't boost::units support this simple operation?
There's actually an alternate formula that does work:
M = 0 For i = 1..N M += (X_i - M)/i
The normal M = \sum X_i / N fails because of two operators, + and /, not just +. If you support that, I'm not sure what the point of using absolute in the first place is.
I have no formal physics education, but intuitively, adding two absolute temperatures doesn't seem really like a mistake to me, even if it's an odd thing to do.
In the case of the average, the addition gives an intermediate result which has no meaning by itself. This is forbidden by design. If this isn't what you need, don't use absolute.
In Christ, Steven Watanabe
Thank you Steven for the clarifications and guidance. I am well aware of this alternate form for calculating a mean. The matter is - eventually, when a user is confronted with such a barrier, I find it more likely that he/she will choose the easy way out: take the .value()s, sum, divide by N, and recreate the quantity (::fromValue()). All the checks and validations go down the drain. So I was hoping to get the reasoning behind the exclusion of the operators '+' and '/' for absolute quantities. In my eyes there's not much difference between summing two absolute quantities of mass density and two absolute temperatures. Surely, with most units the absolute and relative roles are implicitly interchanged without a hassle. My concern is whether denying the use of '+' and '/' on absolute temperatures justified and desirable, in light of it's probable effect. Additionally, here is a use case for absolute temperature ratios, for your consideration: https://www.grc.nasa.gov/www/K-12/airplane/etr.html Thanks again for your time.
On Fri, Jan 1, 2016 at 9:25 AM, Itzik
So I was hoping to get the reasoning behind the exclusion of the operators '+' and '/' for absolute quantities. In my eyes there's not much difference between summing two absolute quantities of mass density and two absolute temperatures.
He gave the explanation. Adding two absolute quantities does not, itself, have meaning, or at least not as an absolute quantity. If you allow that operation directly, you're just introducing a way for users to make a mistake that otherwise would have been correctly caught at compile time. These are some of the kinds of errors that such a unit library aims to prevent, so allowing the operation would go against the idea of the library. -- -Matt Calabrese
AMDG On 01/01/2016 10:25 AM, Itzik wrote:
Additionally, here is a use case for absolute temperature ratios, for your consideration: https://www.grc.nasa.gov/www/K-12/airplane/etr.html
Multiplication and division of temperatures can make sense--but only in Kelvin. A well-known example would be: PV = nRT. In Christ, Steven Watanabe
participants (3)
-
Itzik
-
Matt Calabrese
-
Steven Watanabe