Skip to content

Commit

Permalink
Merge pull request #197 from dynatrace-oss/test-improvement
Browse files Browse the repository at this point in the history
use strictfp in test
  • Loading branch information
oertl authored Dec 15, 2023
2 parents 28d0893 + 112567a commit 985936d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/test/java/com/dynatrace/hash4j/distinctcount/BigInt.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static BigInt ceil(double d) {
return fromIntDouble(Math.ceil(d));
}

private static BigInt fromIntDouble(double d) {
private static strictfp BigInt fromIntDouble(double d) {
checkArgument(d < TWO_POW_PLUS_126_DOUBLE);
if (d >= TWO_POW_PLUS_63_DOUBLE) {
long high = (long) (d * TWO_POW_MINUS_63_DOUBLE);
Expand All @@ -93,7 +93,7 @@ private static BigInt fromIntDouble(double d) {
}
}

public double asDouble() {
public strictfp double asDouble() {
return high * TWO_POW_PLUS_63_DOUBLE + low;
}

Expand Down
13 changes: 7 additions & 6 deletions src/test/java/com/dynatrace/hash4j/distinctcount/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,27 @@ public final class TestUtils {

private TestUtils() {}

public static long[] getDistinctCountValues(long min, long max, double relativeIncrement) {
public static strictfp long[] getDistinctCountValues(
long min, long max, double relativeIncrement) {
List<Long> distinctCounts = new ArrayList<>();
for (long c = max;
c >= min;
c = Math.min(c - 1, (long) Math.ceil(c / (1. + relativeIncrement)))) {
final double factor = 1. / (1. + relativeIncrement);
for (long c = max; c >= min; c = Math.min(c - 1, (long) Math.ceil(c * factor))) {
distinctCounts.add(c);
}
Collections.reverse(distinctCounts);
return distinctCounts.stream().mapToLong(Long::valueOf).toArray();
}

public static List<BigInt> getDistinctCountValues(double max, double relativeIncrement) {
public static strictfp List<BigInt> getDistinctCountValues(double max, double relativeIncrement) {
checkArgument(max >= 1.);
List<BigInt> distinctCounts = new ArrayList<>();
BigInt c = BigInt.ceil(max);
final double factor = 1. / (1. + relativeIncrement);
while (c.isPositive()) {
distinctCounts.add(c.copy());
double d = c.asDouble();
c.decrement();
c.min(BigInt.ceil(d / (1. + relativeIncrement)));
c.min(BigInt.ceil(d * factor));
}
Collections.reverse(distinctCounts);
return distinctCounts;
Expand Down

0 comments on commit 985936d

Please sign in to comment.