2424import static java .lang .Math .log ;
2525import static java .lang .Math .pow ;
2626import static java .lang .Math .round ;
27+ import static java .util .Arrays .fill ;
2728
2829import java .util .Comparator ;
2930
@@ -217,7 +218,7 @@ public static String nanoSecToString(final long nS) {
217218
218219 /**
219220 * Returns the given time in milliseconds formatted as Hours:Min:Sec.mSec
220- * @param mS the given nanoseconds
221+ * @param mS the given milliseconds
221222 * @return the given time in milliseconds formatted as Hours:Min:Sec.mSec
222223 */
223224 public static String milliSecToString (final long mS ) {
@@ -244,40 +245,20 @@ public static String zeroPad(final String s, final int fieldLength) {
244245
245246 /**
246247 * Prepend or postpend the given string with the given character to fill the given field length.
247- * If the given string is equal or greater than the given field length, it will be returned
248- * without modification.
248+ * If the given string is equal to or greater than the given field length, it will be returned without modification.
249249 * @param s the given string
250250 * @param fieldLength the desired field length
251251 * @param padChar the desired pad character
252252 * @param postpend if true append the pacCharacters to the end of the string.
253- * @return prepended or postpended given string with the given character to fill the given field
254- * length.
253+ * @return prepended or postpended given string with the given character to fill the given field length.
255254 */
256- public static String characterPad (final String s , final int fieldLength , final char padChar ,
257- final boolean postpend ) {
258- final char [] chArr = s .toCharArray ();
259- final int sLen = chArr .length ;
255+ public static String characterPad (final String s , final int fieldLength , final char padChar , final boolean postpend ) {
256+ final int sLen = s .length ();
260257 if (sLen < fieldLength ) {
261- final char [] out = new char [fieldLength ];
262- final int blanks = fieldLength - sLen ;
263-
264- if (postpend ) {
265- for (int i = 0 ; i < sLen ; i ++) {
266- out [i ] = chArr [i ];
267- }
268- for (int i = sLen ; i < fieldLength ; i ++) {
269- out [i ] = padChar ;
270- }
271- } else { //prepend
272- for (int i = 0 ; i < blanks ; i ++) {
273- out [i ] = padChar ;
274- }
275- for (int i = blanks ; i < fieldLength ; i ++) {
276- out [i ] = chArr [i - blanks ];
277- }
278- }
279-
280- return String .valueOf (out );
258+ final char [] cArr = new char [fieldLength - sLen ];
259+ fill (cArr , padChar );
260+ final String addstr = String .valueOf (cArr );
261+ return (postpend ) ? s .concat (addstr ) : addstr .concat (s );
281262 }
282263 return s ;
283264 }
@@ -376,8 +357,8 @@ public static int ceilingIntPowerOf2(final int n) {
376357 }
377358
378359 /**
379- * Computes the long ceiling power of 2 within the range [1, 2^30 ]. This is the smallest positive power
380- * of 2 that is equal to or greater than the given n and a mathematical integer .
360+ * Computes the long ceiling power of 2 within the range [1, 2^62 ]. This is the smallest positive power
361+ * of 2 that is equal to or greater than the given n and a mathematical long .
381362 *
382363 * <p>For:
383364 * <ul>
@@ -550,56 +531,60 @@ public static double powerSeriesNextDouble(final int ppb, final double curPoint,
550531 }
551532
552533 /**
553- * Computes the ceiling power of given <i>base </i> and <i>n </i> as doubles .
554- * This is the smallest positive power
555- * of <i>base</i> that equal to or greater than the given <i>n</i> and equal to a mathematical integer.
534+ * Returns the ceiling of a given <i>n </i> given a <i>base </i>, where the ceiling is an integral power of the base .
535+ * This is the smallest positive power of <i>base</i> that is equal to or greater than the given <i>n</i>
536+ * and equal to a mathematical integer.
556537 * The result of this function is consistent with {@link #ceilingIntPowerOf2(int)} for values
557538 * less than one. I.e., if <i>n < 1,</i> the result is 1.
558539 *
559- * @param base The base in the expression ⌈base<sup>n</sup>⌉.
540+ * <p>The formula is: <i>base<sup>ceiling(log<sub>base</sub>(x))</sup></i></p>
541+ *
542+ * @param base The number in the expression ⌈base<sup>n</sup>⌉.
560543 * @param n The input argument.
561544 * @return the ceiling power of <i>base</i> as a double and equal to a mathematical integer.
562545 */
563546 public static double ceilingPowerBaseOfDouble (final double base , final double n ) {
564547 final double x = n < 1.0 ? 1.0 : n ;
565- return pow (base , ceil (logBaseOfX (base , x )));
548+ return Math . round ( pow (base , ceil (logBaseOfX (base , x ) )));
566549 }
567550
568551 /**
569- * Computes the floor power of given <i>base </i> and <i>n </i> as doubles .
570- * This is the largest positive power
571- * of <i>base</i> that equal to or less than the given n and equal to a mathematical integer.
552+ * Computes the floor of a given <i>n </i> given <i>base </i>, where the floor is an integral power of the base .
553+ * This is the largest positive power of <i>base</i> that is equal to or less than the given <i>n</i>
554+ * and equal to a mathematical integer.
572555 * The result of this function is consistent with {@link #floorPowerOf2(int)} for values
573556 * less than one. I.e., if <i>n < 1,</i> the result is 1.
574557 *
575- * @param base The base in the expression ⌊base<sup>n</sup>⌋.
558+ * <p>The formula is: <i>base<sup>floor(log<sub>base</sub>(x))</sup></i></p>
559+ *
560+ * @param base The number in the expression ⌊base<sup>n</sup>⌋.
576561 * @param n The input argument.
577562 * @return the floor power of 2 and equal to a mathematical integer.
578563 */
579564 public static double floorPowerBaseOfDouble (final double base , final double n ) {
580565 final double x = n < 1.0 ? 1.0 : n ;
581- return pow (base , floor (logBaseOfX (base , x )));
566+ return Math . round ( pow (base , floor (logBaseOfX (base , x ) )));
582567 }
583568
584569 // Logarithm related
585570
586571 /**
587- * The log base 2 of the value
572+ * The log<sub>2</sub>( value)
588573 * @param value the given value
589- * @return The log base 2 of the value
574+ * @return log<sub>2</sub>( value)
590575 */
591576 public static double log2 (final double value ) {
592577 return log (value ) / LOG2 ;
593578 }
594579
595580 /**
596- * Returns the logarithm_logBase of x . Example: logB(2.0, x) = log(x) / log(2.0).
597- * @param logBase the base of the logarithm used
581+ * Returns the log<sub>base</sub>(x) . Example, if base = 2.0 : logB(2.0, x) = log(x) / log(2.0).
582+ * @param base The number in the expression log(x) / log(base).
598583 * @param x the given value
599- * @return the logarithm_logBase of x: Example: logB(2.0, x) = log(x) / log(2.0).
584+ * @return the log<sub>base</sub> (x)
600585 */
601- public static double logBaseOfX (final double logBase , final double x ) {
602- return log (x ) / log (logBase );
586+ public static double logBaseOfX (final double base , final double x ) {
587+ return log (x ) / log (base );
603588 }
604589
605590 /**
0 commit comments