-
-
Notifications
You must be signed in to change notification settings - Fork 43
Closed
Labels
Milestone
Description
Clarify the behavior of Q₁ + Q₂
or Q * n
(with n a unitless number) when the unit of measurement of Q
, Q₁
or Q₂
is "shifted". Example of shifted units are:
- Temperature in Celsius, with °C defined as K - 273.15 K.
- Density sigma-t, with σT defined as ρ - 1000 kg/m³ (used in oceanography).
- Other shifted units in other scientific domains?
Taking temperature in °C as an example, addition can happen in at least two different contexts:
- T₁ + T₂ : there is some legitimate uses for such additions, but they are rare.
- T + ΔT : a more common case.
In the T₁ + T₂ case, both quantities must be converted to K before addition. So 20°C + 10°C = 303.15°C because T₂ = 283.15 K. In the T + ΔT case, 10°C is an increment (ΔT). So in this later case 20°C + 10°C = 30°C.
In current API, there is no way to know if a number is an absolute quantity or an increment. So there is no way to know if we are in the T₁ + T₂ case or in the T + ΔT case. If we want to differentiate those quantities, we may need to:
- Add a new method in
UnitConverter
:deltaConvert(double)
, which convert the given value without applying the offset. This is similar todeltaTransform
injava.awt.geom.AffineTransform
. - Introduce a new interface:
Increment<Q extends Quantity<Q>>
. - Defines arithmetic rules as below: in any arithmetic operation like
M₁ + M₂
orM * n
, implementation SHALL do the following steps at least conceptually (implementations are allowed to avoid conversions in some cases provided that the numerical result is the same):- All M values SHALL be converted to system units before addition or multiplication.
- Conversions of
Quantity
instances shall be done withUnitConverter.convert(…)
. - Conversions of
Increment
instances shall be done withUnitConverter.deltaConvert(…)
.
- Conversions of
- Result type is defined by the following table:
Quantity
+Quantity
=Quantity
Quantity
+Increment
=Quantity
Increment
+Quantity
=Quantity
Increment
+Increment
=Increment
Quantity
* n =Quantity
Increment
* n =Increment
- Result value is converted back to the unit of measurement of the first operand (M₁).
- Using
UnitConverter.convert(…)
if the result type isQuantity
. - Using
UnitConverter.deltaConvert(…)
if the result type isIncrement
.
- Using
- All M values SHALL be converted to system units before addition or multiplication.
htreu, otaviojava and keilw