jocull/rust-measurements

Subtracting temperatures causes confusion

thejpster opened this issue · 4 comments

I confused myself for a good 20 minutes today, trying to get the difference between two temperatures. They were both around room temp, but the result was coming up as -272 degrees C.

it took me a while to realise that the difference was 1 degree, and if you interpret that as Kelvin, you get -272 degrees C. I don't know what the correct answer is, but I'm not sure allowing native subtraction and addition for temperatures makes sense.

@thejpster Maybe some example code would help clarify this case? I'm not sure I fully understand what happened, but I see how there could be an issue.

Internally, all the units are treated as some kind of floating point base unit. For temperature I believe it's degrees Celsius. Everything else is a conversion of some kind.

For really highly precise measurements or those that vary greatly in magnitude, I'm sure this is bound to cause a whole load of problems.

Ah! That makes sense... I think, haha. As I wrote in the README I'm pretty far from any kind of math or science expert so I'm sure cases like this where I didn't understand the units are not isolated.

Added a TemperatureDelta type - you can add/subtract to/from a Temperature to get another Temperature and subtract two Temperatures to get a TemperatureDelta.