|
PulpCore | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object pulpcore.math.CoreMath
public class CoreMath
The CoreMath class contains fixed-point arithmetic functions and other useful math functions.
Fixed-point numbers can be used in place of floating-point numbers. Regarding fixed-point numbers:
Addition and subtraction of two fixed-point numbers is done normally, using + and - operators.
Multiplying a fixed-point number by an integer is done normally, using the * operator. The result is a fixed-point number.
Dividing a fixed-point number by an integer (the fixed-point number is the numerator, and the integer is the denominator) is done normally, using the / operator. The result is a fixed-point number.
Field Summary | |
---|---|
static int |
E
|
static int |
FRACTION_BITS
|
static int |
FRACTION_MASK
|
static double |
MAX_DOUBLE_VALUE
The maximum 64-bit floating-point value that a 32-bit fixed-point value can represent. |
static float |
MAX_FLOAT_VALUE
The maximum 32-bit floating-point value that a 32-bit fixed-point value can represent. |
static int |
MAX_INT_VALUE
The maximum integer value that a 32-bit fixed-point value can represent. |
static int |
MAX_VALUE
|
static double |
MIN_DOUBLE_VALUE
The minumum 64-bit floating-point value that a 32-bit fixed-point value can represent. |
static float |
MIN_FLOAT_VALUE
The minumum 32-bit floating-point value that a 32-bit fixed-point value can represent. |
static int |
MIN_INT_VALUE
The minumum integer value that a 32-bit fixed-point value can represent. |
static int |
MIN_VALUE
|
static int |
ONE
|
static int |
ONE_HALF
|
static int |
ONE_HALF_PI
|
static int |
PI
|
static int |
TWO_PI
|
Method Summary | |
---|---|
static int |
abs(int n)
Returns the absolute value of a number. |
static int |
acos(int fx)
Returns the arccosine of the specified fixed-point value. |
static int |
asin(int fx)
Returns the arcsine of the specified fixed-point value. |
static int |
atan(int fx)
Returns the arctangent of the specified fixed-point value. |
static int |
atan2(int fy,
int fx)
Returns in the range from -pi to pi. |
static int |
ceil(int f)
Returns the ceil of a fixed-point value. |
static double |
clamp(double n,
double min,
double max)
Clamps a number between two values. |
static float |
clamp(float n,
float min,
float max)
Clamps a number between two values. |
static int |
clamp(int n,
int min,
int max)
Clamps a number between two values. |
static int |
cos(int fx)
Returns the cosine of the specified fixed-point radian value. |
static int |
cosineInterpolate(int n1,
int n2,
int f)
Performs a 1-dimensional cosine interpolation between values n1 and n2. |
static int |
cot(int fx)
Returns the cotangent of the specified fixed-point radian value. |
static int |
countBits(int n)
Counts the number of "on" bits in an integer. |
static int |
cubicInterpolate(int n0,
int n1,
int n2,
int n3,
int f)
Performs a 1-dimensional cubic interpolation between values n1 and n2. |
static long |
dist(int x1,
int y1,
int x2,
int y2)
|
static int |
div(int f1,
int f2)
Divides the first fixed-point number by the second fixed-point number. |
static long |
div(long f1,
long f2)
Divides the first fixed-point number by the second fixed-point number. |
static int |
floor(int f)
Returns the floor of a fixed-point value (removes the fractional part). |
static int |
fracPart(int f)
Returns the fractional part of a fixed-point value (removes the integer part). |
static int |
intDivCeil(int n,
int d)
Divides the number, n, by the divisor, d, returning the nearest integer greater than or equal to the result. |
static int |
intDivFloor(int n,
int d)
Divides the number, n, by the divisor, d, returning the nearest integer less than or equal to the result. |
static int |
intDivRound(int n,
int d)
Divides the number, n, by the divisor, d, rounding the result to the nearest integer. |
static int |
interpolate(int n1,
int n2,
int f)
Performs a 1-dimensional linear interpolation between values n1 and n2. |
static int |
interpolatedNoise(int fx)
|
static int |
interpolatedNoise(int fx,
int fy)
|
static String |
intToString(int n)
Converts an integer to a base-10 string representation. |
static String |
intToString(int n,
int numFractionalDigits)
Converts a integer to a base-10 string representation using the specified number of fractional digits. |
static String |
intToString(int n,
int minFracDigits,
int maxFracDigits,
boolean grouping)
Converts an integer to a base-10 string representation. |
static boolean |
isPowerOfTwo(int n)
Returns true if the number (greater than 1) is a power of two. |
static int |
log2(int n)
Returns the log base 2 of an integer greater than 0. |
static int |
mul(int f1,
int f2)
Multiplies two fixed-point numbers together. |
static long |
mul(long f1,
long f2)
Multiplies two fixed-point numbers together. |
static int |
mulDiv(int f1,
int f2,
int f3)
Multiplies the first two fixed-point numbers together, then divides by the third fixed-point number. |
static long |
mulDiv(long f1,
long f2,
long f3)
Multiplies the first two fixed-point numbers together, then divides by the third fixed-point number. |
static int |
noise(int n)
|
static int |
noise(int x,
int y)
|
static int |
perlinNoise(int fx,
int persistence,
int numOctaves)
|
static int |
perlinNoise(int fx,
int fy,
int persistence,
int numOctaves)
|
static int |
quickCurveInterpolate(int n1,
int n2,
int f)
|
static boolean |
rand()
Returns a random boolean. |
static double |
rand(double max)
Returns a random double from 0 to max, inclusive |
static double |
rand(double min,
double max)
Returns a random double from min to max, inclusive |
static int |
rand(int max)
Returns a random integer from 0 to max, inclusive |
static int |
rand(int min,
int max)
Returns a random integer from min to max, inclusive |
static boolean |
randChance(int percent)
Returns true if a random event occurs. |
static int |
round(int f)
Returns the fixed-point value rounded to the nearest integer location. |
static int |
sign(double n)
Returns the sign of a number. |
static int |
sign(int n)
Returns the sign of a number. |
static int |
sin(int fx)
Returns the sine of the specified fixed-point radian value. |
static int |
smoothNoise(int x)
|
static int |
smoothNoise(int x,
int y)
|
static int |
sqrt(int fx)
|
static long |
sqrt(long fx)
|
static int |
tan(int fx)
Returns the tangent of the specified fixed-point radian value. |
static double |
toDouble(int f)
Converts a fixed-point value to a double. |
static int |
toFixed(double n)
Converts a double-percsion float to a fixed-point value. |
static int |
toFixed(float n)
Converts a float to a fixed-point value. |
static int |
toFixed(int n)
Converts an integer to a fixed-point value. |
static int |
toFixed(String n)
Converts a String representing a double-percsion float into a fixed-point value. |
static float |
toFloat(int f)
Converts a fixed-point value to a float. |
static int |
toInt(int f)
Converts a fixed-point value to an integer. |
static int |
toIntCeil(int f)
Converts a fixed-point value to an integer. |
static int |
toIntFloor(int f)
Converts a fixed-point value to an integer. |
static int |
toIntRound(int f)
Converts a fixed-point value to an integer. |
static String |
toString(int f)
Converts a fixed-point number to a base-10 string representation. |
static String |
toString(int f,
int numFractionalDigits)
Converts a fixed-point number to a base-10 string representation using the specified number of fractional digits. |
static String |
toString(int f,
int minFracDigits,
int maxFracDigits,
boolean grouping)
Converts a fixed-point number to a base-10 string representation. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int FRACTION_BITS
public static final int FRACTION_MASK
public static final int ONE
public static final int ONE_HALF
public static final int PI
public static final int TWO_PI
public static final int ONE_HALF_PI
public static final int E
public static final int MAX_VALUE
public static final int MIN_VALUE
public static final int MAX_INT_VALUE
public static final int MIN_INT_VALUE
public static final float MAX_FLOAT_VALUE
public static final float MIN_FLOAT_VALUE
public static final double MAX_DOUBLE_VALUE
public static final double MIN_DOUBLE_VALUE
Method Detail |
---|
public static final int toFixed(int n)
public static final int toFixed(float n)
public static final int toFixed(double n)
public static final int toFixed(String n) throws NumberFormatException
NumberFormatException
- if the string does not contain a parsable number.public static final float toFloat(int f)
public static final double toDouble(int f)
public static final int toInt(int f)
public static final int toIntFloor(int f)
public static final int toIntRound(int f)
public static final int toIntCeil(int f)
public static final int fracPart(int f)
public static final int floor(int f)
public static final int ceil(int f)
public static final int round(int f)
public static final String toString(int f)
public static final String toString(int f, int numFractionalDigits)
public static String toString(int f, int minFracDigits, int maxFracDigits, boolean grouping)
f
- the fixed-point numberminFracDigits
- the minimum number of digits to show after
the decimal point.maxFracDigits
- the maximum number of digits to show after
the decimal point.grouping
- if (true, uses the grouping character (',')
to seperate groups in the integer portion of the number.public static final String intToString(int n)
public static final String intToString(int n, int numFractionalDigits)
public static String intToString(int n, int minFracDigits, int maxFracDigits, boolean grouping)
n
- the integerminFracDigits
- the minimum number of digits to show after
the decimal point.maxFracDigits
- the maximum number of digits to show after
the decimal point.grouping
- if (true, uses the grouping character (',')
to seperate groups in the integer portion of the number.public static final boolean isPowerOfTwo(int n)
public static final int countBits(int n)
public static final int log2(int n)
Math.floor(Math.log(n) / Math.log(2))
.
public static final int clamp(int n, int min, int max)
public static final float clamp(float n, float min, float max)
public static final double clamp(double n, double min, double max)
public static final int sign(int n)
public static final int sign(double n)
public static final int abs(int n)
public static final int intDivRound(int n, int d)
public static final int intDivFloor(int n, int d)
public static final int intDivCeil(int n, int d)
public static final int mul(int f1, int f2)
public static final long mul(long f1, long f2)
public static final int div(int f1, int f2)
public static final long div(long f1, long f2)
public static final int mulDiv(int f1, int f2, int f3)
public static final long mulDiv(long f1, long f2, long f3)
public static final int sqrt(int fx)
public static final long sqrt(long fx)
public static long dist(int x1, int y1, int x2, int y2)
public static final int sin(int fx)
public static final int cos(int fx)
public static final int tan(int fx)
public static final int cot(int fx)
public static final int asin(int fx)
public static final int acos(int fx)
public static final int atan(int fx)
public static final int atan2(int fy, int fx)
public static final int rand(int max)
public static final int rand(int min, int max)
public static final double rand(double max)
public static final double rand(double min, double max)
public static final boolean rand()
public static final boolean randChance(int percent)
percent
- The probability of the event occuring, from 0 (never) to 100 (always).public static final int noise(int n)
public static final int noise(int x, int y)
public static final int smoothNoise(int x)
public static final int smoothNoise(int x, int y)
public static final int interpolatedNoise(int fx)
public static final int interpolatedNoise(int fx, int fy)
public static final int perlinNoise(int fx, int persistence, int numOctaves)
fx
- fixed-point valuepersistence
- fixed-point value <= 1.
public static final int perlinNoise(int fx, int fy, int persistence, int numOctaves)
fx
- fixed-point valuefy
- fixed-point valuepersistence
- fixed-point value <= 1.
public static final int interpolate(int n1, int n2, int f)
public static final int cosineInterpolate(int n1, int n2, int f)
public static final int quickCurveInterpolate(int n1, int n2, int f)
public static final int cubicInterpolate(int n0, int n1, int n2, int n3, int f)
|
PulpCore | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |