Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- Reincluded SonarQube step for Dependabot PRs [#575](https://github.com/ie3-institute/PowerSystemUtils/issues/575)

### Fixed
- updated zero divison error issue in Qualityutil[#295](https://github.com/ie3-institute/PowerSystemUtils/issues/295)

## [3.1.0]

### Added
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/edu/ie3/util/quantities/QuantityUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ public static <Q extends Quantity<Q>> boolean isEquivalentRel(Quantity<Q> a, Qua
* of both quantities' value with regard to <i>{@code a}</i>'s value. Both quantities are
* converted into <i>{@code a}</i>'s unit before the comparison.
*
* <p>If {@code a} is 0, the result is just based on strict equality with {@code b}, since no
* relative comparison is possible.
*
* @param a First quantity to compare
* @param b Second quantity to compare
* @param relQuantityTolerance Permissible relative tolerance
Expand All @@ -146,6 +149,10 @@ public static <Q extends Quantity<Q>> boolean isEquivalentRel(
double aVal = a.getValue().doubleValue();
double bVal = b.to(a.getUnit()).getValue().doubleValue();

if (aVal == 0.0) {
return bVal == 0.0;
}

return (Math.abs(aVal - bVal) / Math.abs(aVal)) <= relQuantityTolerance;
}

Expand Down