You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datasketches.apache.org by le...@apache.org on 2022/07/13 21:56:33 UTC
[datasketches-java] 01/01: Extend pwr2SeriesNext and powerSeriesNextDouble to use longs.
This is an automated email from the ASF dual-hosted git repository.
leerho pushed a commit to branch pwr2seriesToLong
in repository https://gitbox.apache.org/repos/asf/datasketches-java.git
commit 205bb5c37796a3ad32c55d4705e4fd6be4429f8b
Author: Lee Rhodes <le...@users.noreply.github.com>
AuthorDate: Mon Jul 11 10:05:45 2022 -0700
Extend pwr2SeriesNext and powerSeriesNextDouble to use longs.
---
src/main/java/org/apache/datasketches/Util.java | 14 +++++++-------
src/test/java/org/apache/datasketches/UtilTest.java | 10 +++++-----
2 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/src/main/java/org/apache/datasketches/Util.java b/src/main/java/org/apache/datasketches/Util.java
index 0074506d..89dcda56 100644
--- a/src/main/java/org/apache/datasketches/Util.java
+++ b/src/main/java/org/apache/datasketches/Util.java
@@ -544,12 +544,12 @@ public final class Util {
* @param curPoint the current point of the series. Must be ≥ 1.
* @return the next point in the power series.
*/
- public static int pwr2SeriesNext(final int ppo, final int curPoint) {
- final int cur = curPoint < 1 ? 1 : curPoint;
+ public static long pwr2SeriesNext(final int ppo, final long curPoint) {
+ final long cur = curPoint < 1L ? 1L : curPoint;
int gi = (int)round(log2(cur) * ppo); //current generating index
- int next;
+ long next;
do {
- next = (int)round(pow(2.0, (double) ++gi / ppo));
+ next = round(pow(2.0, (double) ++gi / ppo));
} while ( next <= curPoint);
return next;
}
@@ -606,18 +606,18 @@ public final class Util {
*
* @param ppb Points-Per-Base, or the number of points per integer powers of base in the series.
* @param curPoint the current point of the series. Must be ≥ 1.0.
- * @param roundToInt if true the output will be rounded to the nearest integer.
+ * @param roundToLong if true the output will be rounded to the nearest long.
* @param logBase the desired base of the logarithms
* @return the next point in the power series.
*/
public static double powerSeriesNextDouble(final int ppb, final double curPoint,
- final boolean roundToInt, final double logBase) {
+ final boolean roundToLong, final double logBase) {
final double cur = curPoint < 1.0 ? 1.0 : curPoint;
double gi = round(logBaseOfX(logBase, cur) * ppb ); //current generating index
double next;
do {
final double n = pow(logBase, ++gi / ppb);
- next = roundToInt ? round(n) : n;
+ next = roundToLong ? round(n) : n;
} while (next <= cur);
return next;
}
diff --git a/src/test/java/org/apache/datasketches/UtilTest.java b/src/test/java/org/apache/datasketches/UtilTest.java
index 931f6a71..1ab20db6 100644
--- a/src/test/java/org/apache/datasketches/UtilTest.java
+++ b/src/test/java/org/apache/datasketches/UtilTest.java
@@ -386,14 +386,14 @@ public class UtilTest {
@Test
public void checkPwr2LawNext() {
- int next = pwr2SeriesNext(2, 1);
+ int next = (int)pwr2SeriesNext(2, 1);
Assert.assertEquals(next, 2);
- next = pwr2SeriesNext(2, 2);
+ next = (int)pwr2SeriesNext(2, 2);
Assert.assertEquals(next, 3);
- next = pwr2SeriesNext(2, 3);
+ next = (int)pwr2SeriesNext(2, 3);
Assert.assertEquals(next, 4);
- next = pwr2SeriesNext(2, 0);
+ next = (int)pwr2SeriesNext(2, 0);
Assert.assertEquals(next, 1);
}
@@ -423,7 +423,7 @@ public class UtilTest {
final int minP = 1;
final int ppo = 4;
- for (int p = minP; p <= maxP; p = pwr2SeriesNext(ppo, p)) {
+ for (int p = minP; p <= maxP; p = (int)pwr2SeriesNext(ppo, p)) {
print(p + " ");
}
println("");
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org