unitsofmeasurement / indriya

JSR 385 - Reference Implementation
Other
119 stars 42 forks source link

Comparing a Quantity of `Double.MAX_VALUE` with a `BigDecimal` value gives unexpected results #362

Closed t-ober closed 2 years ago

t-ober commented 2 years ago

Calling Quantities.getQuantity(Double.MAX_VALUE, Unit).isLessThan() with a BigDecimal number always returns true. This only happens when the BigDecimal value is constructed with a double or a comma-separated String.

Code to reproduce:

ComparableQuantity<ElectricCurrent> maxValue = Quantities.getQuantity(Double.MAX_VALUE, tech.units.indriya.unit.Units.AMPERE);
ComparableQuantity<ElectricCurrent> value = Quantities.getQuantity(new java.math.BigDecimal("1.1"), tech.units.indriya.unit.Units.AMPERE);
System.out.println(maxValue.isLessThan(value));

This seems highly unintuitive. Is this a bug or am I missing something?

andi-huber commented 2 years ago

I believe this is fixed since https://github.com/unitsofmeasurement/indriya/commit/6b70a579f7221db0254c8ced4f52842d01231d0d

keilw commented 2 years ago

I scoped it for 2.1.3, if it was already fixed please verify and consider closing it. The other issues are finished or mostly involve documentation.

t-ober commented 2 years ago

This indeed seems to be resolved! Thanks for the fast reply and of course for maintaining this very helpful project 🙂