-
Notifications
You must be signed in to change notification settings - Fork 97
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
Computing an average temperature #403
Comments
Not a great answer, but I would convert to temperature interval and then back again: |
I hit a similar issue, but subtracting |
More generally speaking, while summing affine quantities makes no sense, computing their mean does. So affine quantities, not just I've not had the need to use use uom::si::f32::{TemperatureInterval as dT, ThermodynamicTemperature as T};
fn temp_difference(t1: T, t2: T) -> dT { t2 - t1 } gives a compilation error or the subtraction `t2 - t1', which prevents these sorts of implementations fn mean_t(t1: T, t2: T) -> T {
let dt: dT = t2 - t1;
t1 + dt / 2.0
}
fn mean_temp(ts: &[T]) -> Option<T> {
if ts.is_empty() { return None }
let n = ts.len() as f32;
let t0: T = ts[0]; // An arbitrary reference value, any `T` will do
let mean_deviation_from_t0: dT = ts.iter().map(|t| t - t0).sum::<dT>() / n;
Some(t0 + mean_deviation_from_t0)
} |
@jacg issue #380 has the explanation for why it is like that. I do wonder if In fact, I believe a similar problem already exists: |
I trust that we agree that this is a restriction imposed by an unfortunate shortcoming of the current implementation details of
... and for any
When you say that
You mean
They cannot possibly be Your
In general, it only makes sense to multiply vector, not affine, quantities. When it comes to quantities like
If your solution is to keep pouring in rice until the number shown by the display doubles, then you'll get the wrong answer precisely because you performed an operation that is only permitted on vector quantities on an affine quantity: you multiplied an affine mass by 2, and multiplying affine quantities doesn't make sense. |
Currently,
ThermodynamicTemperature
values cannot be added together; the module documentation does a good job of explaining why. However, that makes it rather difficult to calculate the average of a collection ofThermodynamicTemperature
values. For non-affine quanities, one can just use.sum()
on an iterator then divide by the number of elements.Is there a recommended way to do this for temperature values?
The text was updated successfully, but these errors were encountered: