|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.planet_ink.coffee_mud.core.CMath
public class CMath
A core singleton class handling various mathematical operations and functions, especially dealing with explicit type conversions, and special string conversions and functions.
| Nested Class Summary | |
|---|---|
static class |
CMath.CompiledOperation
A class representing a single piece of a compiled operation. |
| Method Summary | |
|---|---|
static double |
abs(double d)
|
static float |
abs(float d)
|
static int |
abs(int val)
Returns the absolute value (X>=0) of the given number |
static long |
abs(long val)
Returns the absolute value (X>=0) of the given number |
static long |
absDiff(long x,
long y)
Returns the absolute difference between two numbers |
static boolean |
banyset(int num,
int bitmask)
Returns true if any of the bits represented by the given bitmask are set in the given number. |
static boolean |
banyset(long num,
int bitmask)
Returns true if any of the bits represented by the given bitmask are set in the given number. |
static boolean |
banyset(long num,
long bitmask)
Returns true if any of the bits represented by the given bitmask are set in the given number. |
static int |
bitNumber(long mask)
Returns the first set bit number of the bitmask given |
static boolean |
bset(int num,
int bitmask)
Returns true if the given number has the bits represented by the given bitmask set. |
static boolean |
bset(long num,
int bitmask)
Returns true if the given number has the bits represented by the given bitmask set. |
static boolean |
bset(long num,
long bitmask)
Returns true if the given number has the bits represented by the given bitmask set. |
static boolean |
bset(short num,
short bitmask)
Returns true if the given number has the bits represented by the given bitmask set. |
static double |
ceiling(double d)
|
static float |
ceiling(float d)
|
static java.util.LinkedList<CMath.CompiledOperation> |
compileMathExpression(java.lang.String formula)
Pre-compiles an expression for faster evaluation later on. |
static int |
convertFromRoman(java.lang.String s)
Convert a number from roman numeral to integer. |
static java.lang.String |
convertToRoman(int i)
Convert an integer to its Roman Numeral equivalent Usage: Return=convertToRoman(Number)+"."; |
static double |
div(double a,
double b)
Divide a by b, making sure both are cast to doubles and that the return is precisely double. |
static double |
div(double a,
int b)
Divide a by b, making sure both are cast to doubles and that the return is precisely double. |
static double |
div(double a,
long b)
Divide a by b, making sure both are cast to doubles and that the return is precisely double. |
static double |
div(int a,
double b)
Divide a by b, making sure both are cast to doubles and that the return is precisely double. |
static double |
div(int a,
int b)
Divide a by b, making sure both are cast to doubles and that the return is precisely double. |
static double |
div(long a,
double b)
Divide a by b, making sure both are cast to doubles and that the return is precisely double. |
static double |
div(long a,
long b)
Divide a by b, making sure both are cast to doubles and that the return is precisely double. |
static double |
floor(double d)
|
static float |
floor(float d)
|
static double |
greater(double a,
double b)
Returns greater of two numbers |
static CMath |
instance()
|
static boolean |
isBool(java.lang.String BOOL)
Returns whether the given string is a boolean value Usage: if(isBool(CMD.substring(14))); |
static boolean |
isDouble(java.lang.String DBL)
Returns whether the given string is a double value Usage: if(isDouble(CMD.substring(14))); |
static boolean |
isFloat(java.lang.String DBL)
Returns whether the given string is a float value Usage: if(isFloat(CMD.substring(14))); |
static boolean |
isInteger(java.lang.String INT)
Returns whether the given string is a int value Usage: if(isInteger(CMD.substring(14))); |
static boolean |
isLong(java.lang.String LONG)
Returns whether the given string is a long value Usage: if(isLong(CMD.substring(14))); |
static boolean |
isMathExpression(java.lang.String st)
Returns whether the given string is a valid math expression (5 + 7)/2, etc. |
static boolean |
isMathExpression(java.lang.String st,
double[] vars)
Returns whether the given string is a valid math expression (@x1 + 7)/2, etc. |
static boolean |
isNumber(java.lang.String s)
Returns true if the string is a number (float or int) |
static boolean |
isPct(java.lang.String s)
Returns true if the given string represents a percentage in the form X% where X is any real number. |
static boolean |
isRomanDigit(char c)
Return true if the char is a roman numeral digit |
static boolean |
isRomanNumeral(java.lang.String s)
Returns true if the string is a roman numeral |
static boolean |
isSet(int number,
int bitnumber)
Returns true if the bitnumberth bit (0...) is set in the given number |
static boolean |
isSet(long number,
int bitnumber)
Returns true if the bitnumberth bit (0...) is set in the given number |
static double |
mul(double a,
double b)
Multiply a and b, making sure both are cast to doubles and that the return is precisely double. |
static double |
mul(double a,
int b)
Multiply a and b, making sure both are cast to doubles and that the return is precisely double. |
static double |
mul(double a,
long b)
Multiply a and b, making sure both are cast to doubles and that the return is precisely double. |
static double |
mul(int a,
double b)
Multiply a and b, making sure both are cast to doubles and that the return is precisely double. |
static int |
mul(int a,
int b)
Multiply a and b, making sure both are cast to doubles and that the return is precisely double. |
static double |
mul(long a,
double b)
Multiply a and b, making sure both are cast to doubles and that the return is precisely double. |
static long |
mul(long a,
long b)
Multiply a and b, making sure both are cast to doubles and that the return is precisely double. |
static java.lang.String |
numAppendage(int num)
Return st,nd,rd for a number |
static int |
parseIntExpression(java.lang.String formula)
Returns the result of evaluating the given math expression. |
static int |
parseIntExpression(java.lang.String formula,
double[] vars)
Returns the result of evaluating the given math expression. |
static long |
parseLongExpression(java.lang.String formula)
Returns the result of evaluating the given math expression. |
static long |
parseLongExpression(java.lang.String formula,
double[] vars)
Returns the result of evaluating the given math expression. |
static double |
parseMathExpression(java.util.LinkedList<CMath.CompiledOperation> list,
double[] vars,
double previous)
Parse a pre-compiled expression. |
static double |
parseMathExpression(java.lang.String formula)
Returns the result of evaluating the given math expression. |
static double |
parseMathExpression(java.lang.String formula,
double[] vars)
Returns the result of evaluating the given math expression. |
static long |
pow(long x,
long y)
Raises x to the y power, making sure both are cast to doubles and that the return is rounded off. |
static double |
random()
|
static long |
round(double d)
|
static long |
round(float d)
|
static boolean |
s_bool(java.lang.String BOOL)
Returns the boolean value of a string without crashing Usage: int num=s_bool(CMD.substring(14)); |
static double |
s_double(java.lang.String DOUBLE)
Returns the double value of a string without crashing Usage: dSize = WebIQBase.s_double(WebIQBase.getRes(AttStatsRes,"BlobSize")); |
static float |
s_float(java.lang.String FLOAT)
Returns the floating point value of a string without crashing Usage: lSize = WebIQBase.s_float(WebIQBase.getRes(AttStatsRes,"BlobSize")); |
static int |
s_int(java.lang.String INT)
Returns the integer value of a string without crashing Usage: int num=s_int(CMD.substring(14)); |
static long |
s_long(java.lang.String LONG)
Returns the long value of a string without crashing Usage: lSize = WebIQBase.s_long(WebIQBase.getRes(AttStatsRes,"BlobSize")); |
static int |
s_parseBitIntExpression(java.lang.String[] bits,
java.lang.String val)
Returns a int representing either the given value, or the 2^ power of the comma separated values in the order they appear in the given string list. |
static long |
s_parseBitLongExpression(java.lang.String[] bits,
java.lang.String val)
Returns a long representing either the given value, or the 2^ power of the comma separated values in the order they appear in the given string list. |
static int |
s_parseIntExpression(java.lang.String st)
Returns the result of evaluating the given math expression. |
static int |
s_parseIntExpression(java.lang.String st,
double[] vars)
Returns the result of evaluating the given math expression. |
static int |
s_parseListIntExpression(java.lang.String[] descs,
java.lang.String val)
Returns a int representing either the given value, or the index of the value in the order they appear in the given string list. |
static long |
s_parseListLongExpression(java.lang.String[] descs,
java.lang.String val)
Returns a long representing either the given value, or the index of the value in the order they appear in the given string list. |
static long |
s_parseLongExpression(java.lang.String st)
Returns the result of evaluating the given math expression. |
static long |
s_parseLongExpression(java.lang.String st,
double[] vars)
Returns the result of evaluating the given math expression. |
static double |
s_parseMathExpression(java.lang.String st)
Returns the result of evaluating the given math expression. |
static double |
s_parseMathExpression(java.lang.String st,
double[] vars)
Returns the result of evaluating the given math expression. |
static double |
s_pct(java.lang.String s)
Converts the given string to a floating point number, 1>=N>=0, representing the whole percentage of the string. |
static short |
s_short(java.lang.String SHORT)
Returns the short value of a string without crashing Usage: int num=s_short(CMD.substring(14)); |
static java.lang.Object |
s_valueOf(java.lang.Object[] o,
java.lang.String s)
Returns which object in the object array is same as the string, when cast to a string. |
static int |
setb(int num,
int bitmask)
Returns the given number, after having set the bits represented by the given bit mask. |
static long |
setb(long num,
int bitmask)
Returns the given number, after having set the bits represented by the given bit mask. |
static long |
setb(long num,
long bitmask)
Returns the given number, after having set the bits represented by the given bit mask. |
static void |
setRand(java.util.Random rand)
Replaces the internal Random object with the one passed in. |
static double |
sqrt(double d)
|
static float |
sqrt(float d)
|
static int |
squared(int x)
Returns x, squared, after being case to a double |
static java.lang.String |
toPct(double d)
Converts a percentage 1>d>0 to a string. |
static java.lang.String |
toPct(java.lang.String s)
Converts the string to a double percentage and then converts that back to a percentage. |
static int |
unsetb(int num,
int bitmask)
Unsets those bits in the given number which are turned ON in the given bitmask. |
static long |
unsetb(long num,
int bitmask)
Unsets those bits in the given number which are turned ON in the given bitmask. |
static long |
unsetb(long num,
long bitmask)
Unsets those bits in the given number which are turned ON in the given bitmask. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static final CMath instance()
public static final java.lang.String convertToRoman(int i)
i - Integer to convert
public static final int convertFromRoman(java.lang.String s)
s - the roman numeral string
public static final java.lang.String numAppendage(int num)
num - the number
public static final boolean isRomanDigit(char c)
c - the char
public static final boolean isRomanNumeral(java.lang.String s)
s - the string to test
public static final long absDiff(long x,
long y)
x - the first numbery - the second number
public static final java.lang.Object s_valueOf(java.lang.Object[] o,
java.lang.String s)
o - array of objectss - the string to look
public static final boolean isNumber(java.lang.String s)
s - the string to test
public static final double div(double a,
double b)
a - the dividendb - the divisor
public static final double div(double a,
int b)
a - the dividendb - the divisor
public static final double div(int a,
double b)
a - the dividendb - the divisor
public static final double div(double a,
long b)
a - the dividendb - the divisor
public static final double div(long a,
double b)
a - the dividendb - the divisor
public static final double mul(double a,
double b)
a - the first numberb - the second number
public static final double mul(double a,
int b)
a - the first numberb - the second number
public static final double mul(int a,
double b)
a - the first numberb - the second number
public static final double mul(double a,
long b)
a - the first numberb - the second number
public static final double mul(long a,
double b)
a - the first numberb - the second number
public static final long mul(long a,
long b)
a - the first numberb - the second number
public static final int mul(int a,
int b)
a - the first numberb - the second number
public static final double div(long a,
long b)
a - the dividendb - the divisor
public static final double div(int a,
int b)
a - the dividendb - the divisor
public static final long pow(long x,
long y)
x - the base numbery - the power
public static final int squared(int x)
x - the number to square
public static final boolean bset(short num,
short bitmask)
num - the numberbitmask - the bit mask
public static final boolean bset(int num,
int bitmask)
num - the numberbitmask - the bit mask
public static final boolean bset(long num,
long bitmask)
num - the numberbitmask - the bit mask
public static final boolean bset(long num,
int bitmask)
num - the numberbitmask - the bit mask
public static final int setb(int num,
int bitmask)
num - the numberbitmask - the bitmask
public static final boolean banyset(int num,
int bitmask)
num - the given numberbitmask - the bitmask of bits to check
public static final boolean banyset(long num,
long bitmask)
num - the given numberbitmask - the bitmask of bits to check
public static final boolean banyset(long num,
int bitmask)
num - the given numberbitmask - the bitmask of bits to check
public static final long setb(long num,
int bitmask)
num - the numberbitmask - the bitmask
public static final long setb(long num,
long bitmask)
num - the numberbitmask - the bitmask
public static final int unsetb(int num,
int bitmask)
num - the given numberbitmask - the given bitmask
public static final long unsetb(long num,
long bitmask)
num - the given numberbitmask - the given bitmask
public static final long unsetb(long num,
int bitmask)
num - the given numberbitmask - the given bitmask
public static final boolean isSet(int number,
int bitnumber)
number - the given numberbitnumber - the bit to check (0,1,2...)
public static final boolean isPct(java.lang.String s)
s - the string to check
public static final double s_pct(java.lang.String s)
s - the string to convert
public static final java.lang.String toPct(double d)
d - the number to convert
public static final java.lang.String toPct(java.lang.String s)
s - the string number
public static final boolean isSet(long number,
int bitnumber)
number - the given numberbitnumber - the bit to check (0,1,2...)
public static final boolean isMathExpression(java.lang.String st)
st - the possible math expression
public static final boolean isMathExpression(java.lang.String st,
double[] vars)
st - the possible math expressionvars - the 0 based variables
public static final double s_parseMathExpression(java.lang.String st)
st - a full math expression string
public static final double s_parseMathExpression(java.lang.String st,
double[] vars)
st - a full math expression stringvars - the 0 based variables
public static final long s_parseLongExpression(java.lang.String st)
st - a full math expression string
public static final long s_parseLongExpression(java.lang.String st,
double[] vars)
st - a full math expression stringvars - the 0 based variables
public static final int s_parseIntExpression(java.lang.String st)
st - a full math expression string
public static final int s_parseIntExpression(java.lang.String st,
double[] vars)
st - a full math expression stringvars - the 0 based variables
public static final java.util.LinkedList<CMath.CompiledOperation> compileMathExpression(java.lang.String formula)
formula - the math expression as a string
java.lang.ArithmeticExceptionparseMathExpression(LinkedList, double[], double)
public static final double parseMathExpression(java.util.LinkedList<CMath.CompiledOperation> list,
double[] vars,
double previous)
list - the pre-compiled expressionvars - the variable values
compileMathExpression(StreamTokenizer, boolean)public static final long parseLongExpression(java.lang.String formula)
formula - a full math expression string
public static final long parseLongExpression(java.lang.String formula,
double[] vars)
formula - a full math expression stringvars - the 0 based variables
public static final int parseIntExpression(java.lang.String formula)
throws java.lang.ArithmeticException
formula - a full math expression string
java.lang.ArithmeticException
public static final int parseIntExpression(java.lang.String formula,
double[] vars)
throws java.lang.ArithmeticException
formula - a full math expression stringvars - the 0 based variables
java.lang.ArithmeticException
public static final double parseMathExpression(java.lang.String formula)
throws java.lang.ArithmeticException
formula - a full math expression string
java.lang.ArithmeticException
public static final double parseMathExpression(java.lang.String formula,
double[] vars)
throws java.lang.ArithmeticException
formula - a full math expression stringvars - the 0 based variables
java.lang.ArithmeticExceptionpublic static final long s_long(java.lang.String LONG)
LONG - String to convert
public static final float s_float(java.lang.String FLOAT)
FLOAT - String to convert
public static final double s_double(java.lang.String DOUBLE)
DOUBLE - String to convert
public static final int abs(int val)
val - the number
public static final int bitNumber(long mask)
mask - the bit mask given.
public static final long abs(long val)
val - the number
public static final boolean s_bool(java.lang.String BOOL)
BOOL - Boolean value of string
public static final boolean isBool(java.lang.String BOOL)
BOOL - Boolean value of string
public static final int s_int(java.lang.String INT)
INT - Integer value of string
public static final short s_short(java.lang.String SHORT)
SHORT - Short value of string
public static final boolean isLong(java.lang.String LONG)
LONG - Long value of string
public static final boolean isInteger(java.lang.String INT)
INT - Integer value of string
public static final boolean isFloat(java.lang.String DBL)
DBL - float value of string
public static final int s_parseBitIntExpression(java.lang.String[] bits,
java.lang.String val)
bits - the ordered string values from 0-whatever.val - the expression, or list of string values
public static final long s_parseBitLongExpression(java.lang.String[] bits,
java.lang.String val)
bits - the ordered string values from 0-whatever.val - the expression, or list of string values
public static final void setRand(java.util.Random rand)
rand - the random object to use
public static final long s_parseListLongExpression(java.lang.String[] descs,
java.lang.String val)
descs - the ordered string values from 0-whatever.val - the expression, or list of string values
public static final int s_parseListIntExpression(java.lang.String[] descs,
java.lang.String val)
descs - the ordered string values from 0-whatever.val - the expression, or list of string values
public static final boolean isDouble(java.lang.String DBL)
DBL - double value of string
public static final long round(double d)
d - the real number
Math.round(double)public static final long round(float d)
d - the real number
Math.round(float)public static final double abs(double d)
d - the real number
Math.abs(double)public static final float abs(float d)
d - the real number
Math.abs(float)public static final double random()
Math.random()public static final double floor(double d)
d - the number to get the floor of
Math.floor(double),
ceiling(double)public static final float floor(float d)
d - the number to get the floor of
Math.floor(double),
ceiling(double)public static final double ceiling(double d)
d - the number to get the ceiling of
Math.ceil(double),
floor(double)public static final float ceiling(float d)
d - the number to get the ceiling of
Math.ceil(double),
floor(float)public static final double sqrt(double d)
d - the number to get the square root of
Math.sqrt(double)public static final float sqrt(float d)
d - the number to get the square root of
Math.sqrt(double)
public static final double greater(double a,
double b)
a - first numberb - second number
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||