unitsofmeasurement / uom-systems

Units of Measurement Systems
http://www.uom.systems
Other
36 stars 17 forks source link

UCUM LITER_DM3 unit not equivalent to LITER unit #111

Closed ecolner closed 7 years ago

ecolner commented 7 years ago

The calculation is d(m^3) but we think it should be (dm)^3 because this test fails

Quantity<Volume> oneLiter = Quantities.getQuantity(1, LITER);
System.out.println(oneLiter.to(LITER_DM3).getValue().intValue() == 1);

In UCUM.java the LITER_DM3 constant is defined as

public static final Unit<Volume> LITER_DM3 = addUnit(DECI(Units.CUBIC_METRE));

but it should look something like this

public static final Unit<Volume> LITER_DM3 = addUnit(DECI(METER).multiply(DECI(METER)).multiply(DECI(METER)).asType(Volume.class));
keilw commented 7 years ago

Thanks for pointing that out. While https://github.com/unitsofmeasurement/uom-systems/issues/82 elaborates, that currently LITER_DM3.equals(LITER) won't work because the underlying definitions are simply not identical, the mathematic equivalence must be true. Somehow thought DECI(CUBIC_METER) would get it, but that was a misconception. DECI(Units.METRE).pow(3).asType(Volume.class) is the shorter form and works.

keilw commented 7 years ago

Works now, thanks a lot. I will add a JUnit test based on above assertion, then I'd close this ticket as it is resolved in the master build. An upcoming service release will contain the fix, the 0.7.2-SNAPSHOT already does. In fact, if the conversion-chain between the two units is now the same, https://github.com/unitsofmeasurement/uom-systems/issues/82 could even be solved by this, too.