Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use strictfp in test #197

Merged
merged 1 commit into from
Dec 15, 2023
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
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
Loading