Package org.ojalgo.function.special
Class PowerOf2
- java.lang.Object
-
- org.ojalgo.function.special.PowerOf2
-
- Direct Known Subclasses:
PowerOf2.IntPower
,PowerOf2.LongPower
public abstract class PowerOf2 extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
PowerOf2.IntPower
static class
PowerOf2.LongPower
-
Field Summary
Fields Modifier and Type Field Description int
exponent
private static int[]
INT_POWERS
private static double
LN2
private static long[]
LONG_POWERS
static int
MAX_INT
static long
MAX_LONG
-
Constructor Summary
Constructors Constructor Description PowerOf2(int exp)
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static long
adjustDown(double value)
static int
adjustDown(float value)
static long
adjustUp(double value)
static int
adjustUp(float value)
static int
exponent(double value)
static int
find(int value)
If the input value is a power of 2 then the exponent is returned, if not a negative number is returned.static int
find(long value)
static PowerOf2.IntPower
getIntPower(int exponent)
static PowerOf2.LongPower
getLongPower(int exponent)
static boolean
isPowerOf2(int value)
static boolean
isPowerOf2(long value)
static int
largestNotGreaterThan(int value)
static long
largestNotGreaterThan(long value)
static int
powerOf2Larger(int value)
static int
powerOf2Larger(long value)
static int
powerOf2Smaller(int value)
static int
powerOf2Smaller(long value)
static int
powerOfInt2(int exponent)
static long
powerOfLong2(int exponent)
static int
smallestNotLessThan(int value)
static long
smallestNotLessThan(long value)
-
-
-
Method Detail
-
adjustDown
public static long adjustDown(double value)
- See Also:
largestNotGreaterThan(long)
-
adjustDown
public static int adjustDown(float value)
- See Also:
largestNotGreaterThan(int)
-
adjustUp
public static long adjustUp(double value)
- See Also:
smallestNotLessThan(long)
-
adjustUp
public static int adjustUp(float value)
- See Also:
smallestNotLessThan(int)
-
exponent
public static int exponent(double value)
-
find
public static int find(int value)
If the input value is a power of 2 then the exponent is returned, if not a negative number is returned.
-
find
public static int find(long value)
- See Also:
find(int)
-
getIntPower
public static PowerOf2.IntPower getIntPower(int exponent)
-
getLongPower
public static PowerOf2.LongPower getLongPower(int exponent)
-
isPowerOf2
public static boolean isPowerOf2(int value)
-
isPowerOf2
public static boolean isPowerOf2(long value)
-
largestNotGreaterThan
public static int largestNotGreaterThan(int value)
- Returns:
- The largest power of 2 that is less than or equal to the input (not greater than)
-
largestNotGreaterThan
public static long largestNotGreaterThan(long value)
- Returns:
- The largest power of 2 that is less than or equal to the input (not greater than)
-
powerOf2Larger
public static int powerOf2Larger(int value)
- Returns:
- The smallest integer exponent so that 2^exp >= value.
-
powerOf2Larger
public static int powerOf2Larger(long value)
- Returns:
- The smallest integer exponent so that 2^exp >= value.
-
powerOf2Smaller
public static int powerOf2Smaller(int value)
- Returns:
- The largest integer exponent so that 2^exp <= value.
-
powerOf2Smaller
public static int powerOf2Smaller(long value)
- Returns:
- The largest integer exponent so that 2^exp <= value.
-
powerOfInt2
public static int powerOfInt2(int exponent)
-
powerOfLong2
public static long powerOfLong2(int exponent)
-
smallestNotLessThan
public static int smallestNotLessThan(int value)
- Returns:
- The smallest power of 2 that is greater than or equal to the input (not less than)
-
smallestNotLessThan
public static long smallestNotLessThan(long value)
- Returns:
- The smallest power of 2 that is greater than or equal to the input (not less than)
-
-