From cac729cfb2d2d902ae3341c03237f2d106baac6b Mon Sep 17 00:00:00 2001 From: Florian Kleedorfer Date: Wed, 11 Feb 2026 17:29:11 +0100 Subject: [PATCH 1/2] Bump QUDT version to 3.1.10 .. and fix unit test failures arising from some units having a conversion multiplier of 0. --- pom.xml | 2 +- .../io/github/qudtlib/model/FactorUnits.java | 48 +++++++++++++------ .../io/github/qudtlib/FactorUnitsTests.java | 6 +-- 3 files changed, 38 insertions(+), 18 deletions(-) diff --git a/pom.xml b/pom.xml index 6b573ba5..2cde8986 100644 --- a/pom.xml +++ b/pom.xml @@ -49,7 +49,7 @@ 17 17 UTF-8 - 3.1.5 + 3.1.10 1.33.0 diff --git a/qudtlib-model/src/main/java/io/github/qudtlib/model/FactorUnits.java b/qudtlib-model/src/main/java/io/github/qudtlib/model/FactorUnits.java index b93bfb6b..df0eb1c4 100644 --- a/qudtlib-model/src/main/java/io/github/qudtlib/model/FactorUnits.java +++ b/qudtlib-model/src/main/java/io/github/qudtlib/model/FactorUnits.java @@ -301,7 +301,9 @@ public FactorUnits pow(int exponent) { } return new FactorUnits( this.factorUnits.stream().map(fu -> fu.pow(exponent)).collect(toList()), - this.scaleFactor.pow(exponent, MathContext.DECIMAL128)); + this.scaleFactor.compareTo(BigDecimal.ZERO) != 0 + ? this.scaleFactor.pow(exponent, MathContext.DECIMAL128) + : BigDecimal.ZERO); } public FactorUnits combineWith(FactorUnits other) { @@ -773,13 +775,17 @@ public BigDecimal getConversionMultiplierWithFallbackOne() { if (reduced.hasFactorUnits()) { return reduced.factorUnits.stream() .map( - fu -> - fu.unit - .getFactorUnits() - .getConversionMultiplierWithFallbackOne() - .pow(fu.getExponent(), MathContext.DECIMAL128)) + fu -> { + BigDecimal cm = + fu.unit + .getFactorUnits() + .getConversionMultiplierWithFallbackOne(); + return (cm.compareTo(BigDecimal.ZERO) == 0) + ? BigDecimal.ZERO + : cm.pow(fu.getExponent(), MathContext.DECIMAL128); + }) .reduce((l, r) -> l.multiply(r, MathContext.DECIMAL128)) - .get() + .orElse(BigDecimal.ONE) .multiply(reduced.getScaleFactor(), MathContext.DECIMAL128); } else { if (reduced.factorUnits.isEmpty()) { @@ -802,19 +808,33 @@ public Optional getConversionMultiplierOpt() { .getConversionMultiplierOpt() .map( cm -> - cm.pow( - fu.getExponent(), - MathContext.DECIMAL128))) + cm.compareTo(BigDecimal.ZERO) == 0 + ? BigDecimal.ZERO + : cm.pow( + fu.getExponent(), + MathContext + .DECIMAL128))) .reduce( (leftOpt, rightOpt) -> leftOpt.map( left -> rightOpt.map( right -> - left.multiply( - right, - MathContext - .DECIMAL128)) + (left.compareTo( + BigDecimal + .ZERO) + == 0 + || right + .compareTo( + BigDecimal + .ZERO) + == 0) + ? BigDecimal + .ZERO + : left.multiply( + right, + MathContext + .DECIMAL128)) .orElse(null))) .get() .map(cm -> cm.multiply(reduced.getScaleFactor(), MathContext.DECIMAL128)); diff --git a/qudtlib-test/src/test/java/io/github/qudtlib/FactorUnitsTests.java b/qudtlib-test/src/test/java/io/github/qudtlib/FactorUnitsTests.java index 85fb8d26..185d0d39 100644 --- a/qudtlib-test/src/test/java/io/github/qudtlib/FactorUnitsTests.java +++ b/qudtlib-test/src/test/java/io/github/qudtlib/FactorUnitsTests.java @@ -463,10 +463,10 @@ public void testConversionMultiplierOpt(Unit unit) { String.format( "%s.getConversionMultiplierOpt() is expected to return a value", unit.getIriAbbreviated())); - assertEquals( + assertThat( unit.getFactorUnits().getConversionMultiplierWithFallbackOne(), - result.get(), - String.format("Wrong result for %s", unit.getIriAbbreviated())); + is(closeTo(result.get(), new BigDecimal("0.00001")))); + } else { assertTrue( result.isEmpty(), From 0ba04cddd936f521452343f5751fa4a4838e0b90 Mon Sep 17 00:00:00 2001 From: Florian Kleedorfer Date: Wed, 11 Feb 2026 17:32:04 +0100 Subject: [PATCH 2/2] Bump QUDT version to 3.1.10 .. and fix unit test failures arising from some units having a conversion multiplier of 0. --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1cf8a200..d8847a8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- Bump QUDT version to [3.1.10](https://github.com/qudt/qudt-public-repo/releases/tag/v3.1.10) + ## [7.2.0] - 2026-02-11 ### Added