Skip to content

Commit

Permalink
Move minExcludeNaN, maxExcludeNaN to MoreMath
Browse files Browse the repository at this point in the history
  • Loading branch information
raunaqmorarka authored and sopel39 committed Mar 11, 2022
1 parent 8063841 commit 291b65d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
24 changes: 2 additions & 22 deletions core/trino-main/src/main/java/io/trino/cost/StatisticRange.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import static com.google.common.base.MoreObjects.toStringHelper;
import static com.google.common.base.Preconditions.checkArgument;
import static io.trino.util.MoreMath.maxExcludeNaN;
import static io.trino.util.MoreMath.minExcludeNaN;
import static java.lang.Double.NaN;
import static java.lang.Double.isFinite;
import static java.lang.Double.isInfinite;
Expand Down Expand Up @@ -173,28 +175,6 @@ public StatisticRange addAndCollapseDistinctValues(StatisticRange other)
return new StatisticRange(minExcludeNaN(low, other.low), maxExcludeNaN(high, other.high), newDistinctValues);
}

private static double minExcludeNaN(double v1, double v2)
{
if (isNaN(v1)) {
return v2;
}
if (isNaN(v2)) {
return v1;
}
return min(v1, v2);
}

private static double maxExcludeNaN(double v1, double v2)
{
if (isNaN(v1)) {
return v2;
}
if (isNaN(v2)) {
return v1;
}
return max(v1, v2);
}

@Override
public boolean equals(Object o)
{
Expand Down
22 changes: 22 additions & 0 deletions core/trino-main/src/main/java/io/trino/util/MoreMath.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,26 @@ public static double averageExcludingNaNs(double first, double second)
}
return firstNonNaN(first, second);
}

public static double minExcludeNaN(double v1, double v2)
{
if (isNaN(v1)) {
return v2;
}
if (isNaN(v2)) {
return v1;
}
return min(v1, v2);
}

public static double maxExcludeNaN(double v1, double v2)
{
if (isNaN(v1)) {
return v2;
}
if (isNaN(v2)) {
return v1;
}
return max(v1, v2);
}
}

0 comments on commit 291b65d

Please sign in to comment.