Skip to content

Commit

Permalink
Use infinity for unstorable values
Browse files Browse the repository at this point in the history
  • Loading branch information
otbutz committed Apr 25, 2024
1 parent ff8f2b2 commit fda5a6d
Showing 1 changed file with 4 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,10 @@ public DecimalEncodedValueImpl(String name, int bits, double minStorableValue, d
public void setDecimal(boolean reverse, int edgeId, EdgeIntAccess edgeIntAccess, double value) {
if (!isInitialized())
throw new IllegalStateException("Call init before using EncodedValue " + getName());
if (useMaximumAsInfinity) {
if (Double.isInfinite(value)) {
super.setInt(reverse, edgeId, edgeIntAccess, maxStorableValue);
return;
} else if (value >= maxStorableValue * factor) { // equality is important as maxStorableValue is reserved for infinity
super.uncheckedSet(reverse, edgeId, edgeIntAccess, maxStorableValue - 1);
return;
}
if (useMaximumAsInfinity && value >= maxStorableValue * factor) {
// treat any value larger or equal to maxStorableValue as infinity
super.setInt(reverse, edgeId, edgeIntAccess, maxStorableValue);
return;
} else if (Double.isInfinite(value))
throw new IllegalArgumentException("Value cannot be infinite if useMaximumAsInfinity is false");

Expand Down

0 comments on commit fda5a6d

Please sign in to comment.