Java Utililty Methods Number Round

List of utility methods to do Number Round

Description

The list of methods to do Number Round are organized into topic(s).

Method

longroundUpTo8(long val)
round Up To
long rem = val & 7;
if (rem != 0)
    val += 8L - rem;
return val;
longroundUpToMultiple(long val, int factor)
Round a long value up to a multiple of a factor.
assert (factor > 1);
long c = (val + factor - 1) / factor;
return c * factor;
doubleroundUpToNearest(double number, double nearest)
round Up To Nearest
return Math.ceil(roundToPrecision(number / nearest, 10)) * nearest;
longroundUpToNearestEightBytes(long result)
round Up To Nearest Eight Bytes
if ((result % 8) != 0) {
    result += 8 - (result % 8);
return result;
introundUpToNearestPowerOfTwoIfGreaterThanZero(final int value)
round Up To Nearest Power Of Two If Greater Than Zero
long v = value;
v--;
v |= v >> 1;
v |= v >> 2;
v |= v >> 4;
v |= v >> 8;
v |= v >> 16;
v++;
...
introundUpToPowerOf2(int number)
round Up To Power Of
int rounded = number >= Integer.MAX_VALUE ? Integer.MAX_VALUE
        : (rounded = Integer.highestOneBit(number)) != 0
                ? (Integer.bitCount(number) > 1) ? rounded << 1 : rounded
                : 1;
return rounded;
longroundUpToPowerOf2(long val)
round Up To Power Of
return 1L << log2Ceiling(val);
longroundUpToPowerOf2Factor(long val, long factor)
round Up To Power Of Factor
return (val + (factor - 1)) & ~(factor - 1);
introundUpToPowerOfTwo(int i)
Returns the smallest power of two >= its argument, with several caveats: If the argument is negative but not Integer.MIN_VALUE, the method returns zero.
i--; 
i |= i >>> 1;
i |= i >>> 2;
i |= i >>> 4;
i |= i >>> 8;
i |= i >>> 16;
return i + 1;
introundUpToPowerOfTwo(int p_151236_0_)
Returns the input value rounded up to the next highest power of two.
int j = p_151236_0_ - 1;
j |= j >> 1;
j |= j >> 2;
j |= j >> 4;
j |= j >> 8;
j |= j >> 16;
return j + 1;