|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.levigo.util.base.Numbers
public class Numbers
Credit for the floor(float)
, ceil(float)
and round(float)
methods:
riven: http://riven8192.blogspot.com/2010/02/fastmath-fast-floor.html
Method Summary | |
---|---|
static void |
assertIsWithin(String name,
double value,
double start,
double end)
Throws an IllegalArgumentException if double value does not lie within the
closed double interval [start ..stop ]. |
static void |
assertIsWithin(String name,
float value,
float start,
float end)
Throws an IllegalArgumentException if float value does not lie within the
closed float interval [start ..stop ]. |
static void |
assertIsWithin(String name,
int value,
int start,
int end)
Throws an IllegalArgumentException if integer value does not lie within the
closed integer interval [start ..stop ]. |
static int |
ceil(double x)
A fast implementation of Math.ceil(double) . |
static int |
ceil(float x)
A fast implementation of Math.ceil(double) for float s. |
static double |
clamp(double value,
double min,
double max)
Clamp the value into the range [min..max]. |
static float |
clamp(float value,
float min,
float max)
Clamp the value into the range [min..max]. |
static int |
clamp(int value,
int min,
int max)
Clamp the value into the range [min..max]. |
static long |
clamp(long value,
long min,
long max)
Clamp the value into the range [min..max]. |
static short |
doubleTof2Dot14(double d)
Converts double to 2 bytes with F2Dot14 notation |
static double |
f2Dot14ToDouble(short i)
Converts 16-bit (2 bytes) with F2Dot14 notation to double |
static int |
floor(double x)
A fast implementation of Math.floor(double) . |
static int |
floor(float x)
A fast implementation of Math.floor(double) for float s. |
static boolean |
isNeighbor(double value,
double p,
double epsilon)
Return whether the given value lies within a neighborhood of size 2*epsilon of p. |
static boolean |
isNeighbor(int value,
int p,
int epsilon)
Return whether the given value lies within a neighborhood of size 2*epsilon of p. |
static boolean |
isWithin(double value,
double start,
double end)
Return whether the given value lies within the closed interval [begin..end]. |
static boolean |
isWithin(float value,
float start,
float end)
Return whether the given value lies within the closed interval [begin..end]. |
static boolean |
isWithin(int value,
int start,
int end)
Return whether the given value lies within the closed interval [begin..end]. |
static void |
longToBytesBE(long l,
byte[] buffer,
int offset)
Store the given long in big-endian format into the given buffer at the given offset. |
static void |
longToBytesLE(long l,
byte[] buffer,
int offset)
Store the given long in little-endian format into the given buffer at the given offset. |
static float |
max(float... v)
Return the maximum of all values in the given array. |
static int |
max(int... v)
Return the maximum of all values in the given array. |
static float |
min(float... v)
Return the minimum of all values in the given array. |
static int |
min(int... v)
Return the minimum of all values in the given array. |
static int |
round(double x)
A fast implementation of Math.round(double) . |
static int |
round(float x)
A fast implementation of Math.round(double) for float s. |
static int |
toInfinity(double d)
Round to the next integer so that the rounded value is equal or farther away from zero than the input value. |
static int |
toZero(double d)
Round to the next integer so that the rounded value is equal or closer to zero than the input value. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static int clamp(int value, int min, int max)
value
- min
- max
-
public static float clamp(float value, float min, float max)
value
- min
- max
-
public static double clamp(double value, double min, double max)
value
- min
- max
-
public static long clamp(long value, long min, long max)
value
- min
- max
-
public static int min(int... v)
Integer.MAX_VALUE
will be returned.
public static int max(int... v)
Integer.MIN_VALUE
will be returned.
public static float min(float... v)
Float.MAX_VALUE
will be returned.
public static float max(float... v)
Float.MIN_VALUE
will be returned.
public static boolean isWithin(int value, int start, int end)
value
- start
- end
-
public static boolean isWithin(float value, float start, float end)
value
- start
- end
-
public static boolean isWithin(double value, double start, double end)
value
- start
- end
-
public static void assertIsWithin(String name, int value, int start, int end)
IllegalArgumentException
if integer value
does not lie within the
closed integer interval [start
..stop
].
name
- the name of the value
variable: use in the exception messagevalue
- the integer to be testedstart
- the lower end of the interval: if value
is less than start
then
throw an IllegalArgumentException
end
- the upper end of the interval: if value
is greater than end
then
throw an IllegalArgumentException
public static void assertIsWithin(String name, float value, float start, float end)
IllegalArgumentException
if float value
does not lie within the
closed float interval [start
..stop
].
name
- the name of the value
variable: use in the exception messagevalue
- the float to be testedstart
- the lower end of the interval: if value
is less than start
then
throw an IllegalArgumentException
end
- the upper end of the interval: if value
is greater than end
then
throw an IllegalArgumentException
public static void assertIsWithin(String name, double value, double start, double end)
IllegalArgumentException
if double value
does not lie within the
closed double interval [start
..stop
].
name
- the name of the value
variable: use in the exception messagevalue
- the double to be testedstart
- the lower end of the interval: if value
is less than start
then
throw an IllegalArgumentException
end
- the upper end of the interval: if value
is greater than end
then
throw an IllegalArgumentException
public static boolean isNeighbor(double value, double p, double epsilon)
value
- p
- the pointepsilon
-
public static boolean isNeighbor(int value, int p, int epsilon)
value
- p
- the pointepsilon
-
public static int floor(float x)
Math.floor(double)
for float
s.
x
- the argument
public static int round(float x)
Math.round(double)
for float
s.
x
- the argument
public static int ceil(float x)
Math.ceil(double)
for float
s.
x
- the argument
public static int floor(double x)
Math.floor(double)
.
x
- the argument
public static int round(double x)
Math.round(double)
.
x
- the argument
public static int ceil(double x)
Math.ceil(double)
.
x
- the argument
public static int toZero(double d)
floor(double)
would, otherwise
like ceil(double)
.
d
-
public static int toInfinity(double d)
ceil(double)
would,
otherwise like floor(double)
.
d
-
public static void longToBytesBE(long l, byte[] buffer, int offset)
l
- buffer
- offset
- public static void longToBytesLE(long l, byte[] buffer, int offset)
l
- buffer
- offset
- public static double f2Dot14ToDouble(short i)
public static short doubleTof2Dot14(double d)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |