leerho commented on code in PR #475:
URL: https://github.com/apache/datasketches-java/pull/475#discussion_r1408659590
##########
src/main/java/org/apache/datasketches/common/Util.java:
##########
@@ -550,56 +531,60 @@ public static double powerSeriesNextDouble(final int ppb,
final double curPoint,
}
/**
- * Computes the ceiling power of given <i>base</i> and <i>n</i> as doubles.
- * This is the smallest positive power
- * of <i>base</i> that equal to or greater than the given <i>n</i> and equal
to a mathematical integer.
+ * Returns the ceiling of a given <i>n</i> given a <i>radix</i>, where the
ceiling is an integral power of the radix.
+ * This is the smallest positive power of <i>radix</i> that is equal to or
greater than the given <i>n</i>
+ * and equal to a mathematical integer.
* The result of this function is consistent with {@link
#ceilingIntPowerOf2(int)} for values
* less than one. I.e., if <i>n < 1,</i> the result is 1.
*
- * @param base The base in the expression ⌈base<sup>n</sup>⌉.
+ * <p>The formula is:
<i>radix<sup>ceiling(log<sub>radix</sub>(x))</sup></i></p>
+ *
+ * @param radix The base of the number system.
* @param n The input argument.
- * @return the ceiling power of <i>base</i> as a double and equal to a
mathematical integer.
+ * @return the ceiling power of <i>radix</i> as a double and equal to a
mathematical integer.
*/
- public static double ceilingPowerBaseOfDouble(final double base, final
double n) {
+ public static double ceilingPowerBaseOfDouble(final double radix, final
double n) {
final double x = n < 1.0 ? 1.0 : n;
- return pow(base, ceil(logBaseOfX(base, x)));
+ return Math.round(pow(radix, ceil(logBaseOfX(radix, x))));
}
/**
- * Computes the floor power of given <i>base</i> and <i>n</i> as doubles.
- * This is the largest positive power
- * of <i>base</i> that equal to or less than the given n and equal to a
mathematical integer.
+ * Computes the floor of a given <i>n</i> given <i>radix</i>, where the
floor is an integral power of the radix.
+ * This is the largest positive power of <i>radix</i> that is equal to or
less than the given <i>n</i>
+ * and equal to a mathematical integer.
* The result of this function is consistent with {@link
#floorPowerOf2(int)} for values
* less than one. I.e., if <i>n < 1,</i> the result is 1.
*
- * @param base The base in the expression ⌊base<sup>n</sup>⌋.
+ * <p>The formula is:
<i>radix<sup>floor(log<sub>radix</sub>(x))</sup></i></p>
+ *
+ * @param radix The base of the number system.
* @param n The input argument.
* @return the floor power of 2 and equal to a mathematical integer.
*/
- public static double floorPowerBaseOfDouble(final double base, final double
n) {
+ public static double floorPowerBaseOfDouble(final double radix, final double
n) {
final double x = n < 1.0 ? 1.0 : n;
- return pow(base, floor(logBaseOfX(base, x)));
+ return Math.round(pow(radix, floor(logBaseOfX(radix, x))));
}
// Logarithm related
/**
- * The log base 2 of the value
+ * The log<sub>2</sub>(value)
* @param value the given value
- * @return The log base 2 of the value
+ * @return log<sub>2</sub>(value)
*/
public static double log2(final double value) {
return log(value) / LOG2;
}
/**
- * Returns the logarithm_logBase of x. Example: logB(2.0, x) = log(x) /
log(2.0).
- * @param logBase the base of the logarithm used
+ * Returns the log<sub>radix</sub>(x). Example: logB(2.0, x) = log(x) /
log(2.0).
Review Comment:
Jon already caught this. Will fix.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]