unitsofmeasurement / unit-api

Units of Measurement API
http://unitsofmeasurement.github.io/unit-api/
Other
180 stars 42 forks source link

Fix apparent typo in JavaDoc of Quantity #254

Open vorburger opened 9 months ago

vorburger commented 9 months ago

@keilw


This change is Reviewable

vorburger commented 9 months ago

should be 2°C + 1°C = 276.15°C

Wait, what? Is that a typo, or intentional? It doesn't make sense to me, like this... adding two quantities (2+1) of the same °C unit, becomes a 276.15°C, really?

keilw commented 9 months ago

Yes, that's the whole point of Quantity.Scale.

Check out the Indriya (RI) TemperatureTest or QuantitiesTest by Seshat, another compatible implementation.

As well as TemperatureDemo for

Ask @desruisseaux for the motivation.

desruisseaux commented 9 months ago

Hello @vorburger

adding two quantities (2+1) of the same °C unit, becomes a 276.15°C, really?

Yes, really at least in some cases for the particular case of °C. Actually it depends on whether 1°C is an absolute temperature or an increment. This is why there is a Quantity.Scale enumeration with two values: ABSOLUTE and RELATIVE.

If 1°C is an increment (Scale.RELATIVE), then 2°C + 1°C is equal to 3°C. But if 1°C is a temperature measurement (Scale.ABSOLUTE), then the calculation must be done in K. This is required by thermodynamic laws. So 2°C + 1°C is equal to 275.15 K + 274.15 K = 549.30 K = 276.15°C. The reason is that we are computing the amount of energy in a system.

So if you want 2°C + 1°C = 3°C, you need to tell the library that 1°C is an increment rather than an absolute measurement. This ambiguity exists for °C and not for other standard units (ignoring °F) because °C has a zero which is shifted compared to the base SI unit. For non-shifted units, the distinction between absolute and relative makes no difference, because the shift is zero.

desruisseaux commented 9 months ago

A few resources are below. We have to be careful with the answers of this kind of forum as they may sometime be questionable, but the high-ranked answers have good chances to be good resources:

keilw commented 9 months ago

@vorburger Any chance you could fix this PR? As it's just a single digit, we could also close it and address the viable part of it separately.