public class Numbers extends Object
floor(float)
, ceil(float)
and round(float)
methods:
riven: http://riven8192.blogspot.com/2010/02/fastmath-fast-floor.htmlModifier and Type | Method and Description |
---|---|
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 float[] |
doubleArrayToFloatArray(double[] doubleArray)
converts a double array to a float array
|
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 double[] |
floatArrayToDoubleArray(float[] floatArray)
converts a float array to a double array
|
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 double |
interpolate(double x,
double xmin,
double xmax,
double ymin,
double ymax)
For a given value of x, Interpolate calculates the y value on the line defined by the two points
(xmin, ymin) and (xmax, ymax).
|
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.
|
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 argumentpublic static int round(float x)
Math.round(double)
for float
s.x
- the argumentpublic static int ceil(float x)
Math.ceil(double)
for float
s.x
- the argumentpublic static int floor(double x)
Math.floor(double)
.x
- the argumentpublic static int round(double x)
Math.round(double)
.x
- the argumentpublic static int ceil(double x)
Math.ceil(double)
.x
- the argumentpublic 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)
public static float[] doubleArrayToFloatArray(double[] doubleArray)
doubleArray
- the array to convertpublic static double[] floatArrayToDoubleArray(float[] floatArray)
floatArray
- the array to convertpublic static double interpolate(double x, double xmin, double xmax, double ymin, double ymax)
x
- x-coordinate where to interpolatexmin
- x-coordinate of the lower pointxmax
- x-coordinate of the higher pointymin
- y-coordinate fo the lower pointymax
- y-coordinate of the higher pointCopyright © 2024 levigo holding gmbh. All rights reserved.