com.planet_ink.coffee_mud.core
Class CMath

java.lang.Object
  extended by com.planet_ink.coffee_mud.core.CMath

public class CMath
extends java.lang.Object

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

instance

public static final CMath instance()

convertToRoman

public static final java.lang.String convertToRoman(int i)
Convert an integer to its Roman Numeral equivalent Usage: Return=convertToRoman(Number)+".";

Parameters:
i - Integer to convert
Returns:
String Converted integer

convertFromRoman

public static final int convertFromRoman(java.lang.String s)
Convert a number from roman numeral to integer.

Parameters:
s - the roman numeral string
Returns:
the int

numAppendage

public static final java.lang.String numAppendage(int num)
Return st,nd,rd for a number

Parameters:
num - the number
Returns:
the st,nd,rd appendage only

isRomanDigit

public static final boolean isRomanDigit(char c)
Return true if the char is a roman numeral digit

Parameters:
c - the char
Returns:
true if is roman

isRomanNumeral

public static final boolean isRomanNumeral(java.lang.String s)
Returns true if the string is a roman numeral

Parameters:
s - the string to test
Returns:
true if a roman numeral, false otherwise

absDiff

public static final long absDiff(long x,
                                 long y)
Returns the absolute difference between two numbers

Parameters:
x - the first number
y - the second number
Returns:
the absolute difference (x-y)*(-1 if <)

s_valueOf

public static final 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.

Parameters:
o - array of objects
s - the string to look
Returns:
the object or null

isNumber

public static final boolean isNumber(java.lang.String s)
Returns true if the string is a number (float or int)

Parameters:
s - the string to test
Returns:
true if a number, false otherwise

div

public static final double div(double a,
                               double b)
Divide a by b, making sure both are cast to doubles and that the return is precisely double.

Parameters:
a - the dividend
b - the divisor
Returns:
the quotient

div

public static final double div(double a,
                               int b)
Divide a by b, making sure both are cast to doubles and that the return is precisely double.

Parameters:
a - the dividend
b - the divisor
Returns:
the quotient

div

public static final double div(int a,
                               double b)
Divide a by b, making sure both are cast to doubles and that the return is precisely double.

Parameters:
a - the dividend
b - the divisor
Returns:
the quotient

div

public static final double div(double a,
                               long b)
Divide a by b, making sure both are cast to doubles and that the return is precisely double.

Parameters:
a - the dividend
b - the divisor
Returns:
the quotient

div

public static final double div(long a,
                               double b)
Divide a by b, making sure both are cast to doubles and that the return is precisely double.

Parameters:
a - the dividend
b - the divisor
Returns:
the quotient

mul

public static final double mul(double a,
                               double b)
Multiply a and b, making sure both are cast to doubles and that the return is precisely double.

Parameters:
a - the first number
b - the second number
Returns:
the retult of multiplying a and b

mul

public static final double mul(double a,
                               int b)
Multiply a and b, making sure both are cast to doubles and that the return is precisely double.

Parameters:
a - the first number
b - the second number
Returns:
the retult of multiplying a and b

mul

public static final double mul(int a,
                               double b)
Multiply a and b, making sure both are cast to doubles and that the return is precisely double.

Parameters:
a - the first number
b - the second number
Returns:
the retult of multiplying a and b

mul

public static final double mul(double a,
                               long b)
Multiply a and b, making sure both are cast to doubles and that the return is precisely double.

Parameters:
a - the first number
b - the second number
Returns:
the retult of multiplying a and b

mul

public static final double mul(long a,
                               double b)
Multiply a and b, making sure both are cast to doubles and that the return is precisely double.

Parameters:
a - the first number
b - the second number
Returns:
the retult of multiplying a and b

mul

public static final long mul(long a,
                             long b)
Multiply a and b, making sure both are cast to doubles and that the return is precisely double.

Parameters:
a - the first number
b - the second number
Returns:
the retult of multiplying a and b

mul

public static final int mul(int a,
                            int b)
Multiply a and b, making sure both are cast to doubles and that the return is precisely double.

Parameters:
a - the first number
b - the second number
Returns:
the retult of multiplying a and b

div

public static final double div(long a,
                               long b)
Divide a by b, making sure both are cast to doubles and that the return is precisely double.

Parameters:
a - the dividend
b - the divisor
Returns:
the quotient

div

public static final double div(int a,
                               int b)
Divide a by b, making sure both are cast to doubles and that the return is precisely double.

Parameters:
a - the dividend
b - the divisor
Returns:
the quotient

pow

public static final 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.

Parameters:
x - the base number
y - the power
Returns:
x to the y power, rounded off

squared

public static final int squared(int x)
Returns x, squared, after being case to a double

Parameters:
x - the number to square
Returns:
x, squared, and rounded off.

bset

public static final boolean bset(short num,
                                 short bitmask)
Returns true if the given number has the bits represented by the given bitmask set.

Parameters:
num - the number
bitmask - the bit mask
Returns:
true if the bits are set, false otherwise

bset

public static final boolean bset(int num,
                                 int bitmask)
Returns true if the given number has the bits represented by the given bitmask set.

Parameters:
num - the number
bitmask - the bit mask
Returns:
true if the bits are set, false otherwise

bset

public static final boolean bset(long num,
                                 long bitmask)
Returns true if the given number has the bits represented by the given bitmask set.

Parameters:
num - the number
bitmask - the bit mask
Returns:
true if the bits are set, false otherwise

bset

public static final boolean bset(long num,
                                 int bitmask)
Returns true if the given number has the bits represented by the given bitmask set.

Parameters:
num - the number
bitmask - the bit mask
Returns:
true if the bits are set, false otherwise

setb

public static final int setb(int num,
                             int bitmask)
Returns the given number, after having set the bits represented by the given bit mask.

Parameters:
num - the number
bitmask - the bitmask
Returns:
the number | the bitmask

banyset

public static final boolean banyset(int num,
                                    int bitmask)
Returns true if any of the bits represented by the given bitmask are set in the given number.

Parameters:
num - the given number
bitmask - the bitmask of bits to check
Returns:
true if any bits from the mask are set

banyset

public static final boolean banyset(long num,
                                    long bitmask)
Returns true if any of the bits represented by the given bitmask are set in the given number.

Parameters:
num - the given number
bitmask - the bitmask of bits to check
Returns:
true if any bits from the mask are set

banyset

public static final boolean banyset(long num,
                                    int bitmask)
Returns true if any of the bits represented by the given bitmask are set in the given number.

Parameters:
num - the given number
bitmask - the bitmask of bits to check
Returns:
true if any bits from the mask are set

setb

public static final long setb(long num,
                              int bitmask)
Returns the given number, after having set the bits represented by the given bit mask.

Parameters:
num - the number
bitmask - the bitmask
Returns:
the number | the bitmask

setb

public static final long setb(long num,
                              long bitmask)
Returns the given number, after having set the bits represented by the given bit mask.

Parameters:
num - the number
bitmask - the bitmask
Returns:
the number | the bitmask

unsetb

public static final int unsetb(int num,
                               int bitmask)
Unsets those bits in the given number which are turned ON in the given bitmask.

Parameters:
num - the given number
bitmask - the given bitmask
Returns:
the number without the bitmasks bits turned on.

unsetb

public static final long unsetb(long num,
                                long bitmask)
Unsets those bits in the given number which are turned ON in the given bitmask.

Parameters:
num - the given number
bitmask - the given bitmask
Returns:
the number without the bitmasks bits turned on.

unsetb

public static final long unsetb(long num,
                                int bitmask)
Unsets those bits in the given number which are turned ON in the given bitmask.

Parameters:
num - the given number
bitmask - the given bitmask
Returns:
the number without the bitmasks bits turned on.

isSet

public static final boolean isSet(int number,
                                  int bitnumber)
Returns true if the bitnumberth bit (0...) is set in the given number

Parameters:
number - the given number
bitnumber - the bit to check (0,1,2...)
Returns:
true if the given bitnumberth bit is set

isPct

public static final 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.

Parameters:
s - the string to check
Returns:
true if it is a percentage, false otherwise

s_pct

public static final 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. The string format is either X or X%, where 100>=X>=0 If the format is bad, 0.0 is returned.

Parameters:
s - the string to convert
Returns:
the string converted to a real number

toPct

public static final java.lang.String toPct(double d)
Converts a percentage 1>d>0 to a string.

Parameters:
d - the number to convert
Returns:
the percentage string.

toPct

public static final java.lang.String toPct(java.lang.String s)
Converts the string to a double percentage and then converts that back to a percentage.

Parameters:
s - the string number
Returns:
the percentage %

isSet

public static final boolean isSet(long number,
                                  int bitnumber)
Returns true if the bitnumberth bit (0...) is set in the given number

Parameters:
number - the given number
bitnumber - the bit to check (0,1,2...)
Returns:
true if the given bitnumberth bit is set

isMathExpression

public static final boolean isMathExpression(java.lang.String st)
Returns whether the given string is a valid math expression (5 + 7)/2, etc. Does this by evaluating the expression and returning false if an error is found. No variables are allowed.

Parameters:
st - the possible math expression
Returns:
true if it is a math expression

isMathExpression

public static final boolean isMathExpression(java.lang.String st,
                                             double[] vars)
Returns whether the given string is a valid math expression (@x1 + 7)/2, etc. Does this by evaluating the expression and returning false if an error is found. All necessary variables MUST be included (@x1=vars[0])

Parameters:
st - the possible math expression
vars - the 0 based variables
Returns:
true if it is a math expression

s_parseMathExpression

public static final double s_parseMathExpression(java.lang.String st)
Returns the result of evaluating the given math expression. An expression can be a double or int number, or a full expression using ()+-/*?<>. Variable @xx will refer to current computed value. Returns 0.0 on any parsing error

Parameters:
st - a full math expression string
Returns:
the result of the expression

s_parseMathExpression

public static final double s_parseMathExpression(java.lang.String st,
                                                 double[] vars)
Returns the result of evaluating the given math expression. An expression can be a double or int number, or a full expression using ()+-/*?<>. Variables are included as @x1, etc.. The given variable values list is 0 based, so @x1 = vars[0]. Variable @xx will refer to current computed value. Returns 0.0 on any parsing error

Parameters:
st - a full math expression string
vars - the 0 based variables
Returns:
the result of the expression

s_parseLongExpression

public static final long s_parseLongExpression(java.lang.String st)
Returns the result of evaluating the given math expression. An expression can be a double or int number, or a full expression using ()+-/*?<>. Variable @xx will refer to current computed value. Rounds the result to a long. Returns 0 on any parsing error

Parameters:
st - a full math expression string
Returns:
the result of the expression

s_parseLongExpression

public static final long s_parseLongExpression(java.lang.String st,
                                               double[] vars)
Returns the result of evaluating the given math expression. An expression can be a double or int number, or a full expression using ()+-/*?<>. Variables are included as @x1, etc.. The given variable values list is 0 based, so @x1 = vars[0]. Variable @xx will refer to current computed value. Rounds the result to a long. Returns 0 on any parsing error

Parameters:
st - a full math expression string
vars - the 0 based variables
Returns:
the result of the expression

s_parseIntExpression

public static final int s_parseIntExpression(java.lang.String st)
Returns the result of evaluating the given math expression. An expression can be a double or int number, or a full expression using ()+-/*?<>. Variable @xx will refer to current computed value. Round the result to an integer. Returns 0 on any parsing error

Parameters:
st - a full math expression string
Returns:
the result of the expression

s_parseIntExpression

public static final int s_parseIntExpression(java.lang.String st,
                                             double[] vars)
Returns the result of evaluating the given math expression. An expression can be a double or int number, or a full expression using ()+-/*?<>. Variables are included as @x1, etc.. The given variable values list is 0 based, so @x1 = vars[0]. Variable @xx will refer to current computed value. Rounds the result to an integer. Returns 0 on any parsing error

Parameters:
st - a full math expression string
vars - the 0 based variables
Returns:
the result of the expression

compileMathExpression

public static final java.util.LinkedList<CMath.CompiledOperation> compileMathExpression(java.lang.String formula)
Pre-compiles an expression for faster evaluation later on.

Parameters:
formula - the math expression as a string
Returns:
the pre-compiled expression
Throws:
java.lang.ArithmeticException
See Also:
parseMathExpression(LinkedList, double[], double)

parseMathExpression

public static final double parseMathExpression(java.util.LinkedList<CMath.CompiledOperation> list,
                                               double[] vars,
                                               double previous)
Parse a pre-compiled expression. Requires a vars variable of at least 10 entries to ensure NO exceptions (other than /0).

Parameters:
list - the pre-compiled expression
vars - the variable values
Returns:
the final value
See Also:
compileMathExpression(StreamTokenizer, boolean)

parseLongExpression

public static final long parseLongExpression(java.lang.String formula)
Returns the result of evaluating the given math expression. An expression can be a double or int number, or a full expression using ()+-/*?<>. Variable @xx will refer to current computed value. Rounds the result to a long Throws an exception on any parsing error

Parameters:
formula - a full math expression string
Returns:
the result of the expression

parseLongExpression

public static final long parseLongExpression(java.lang.String formula,
                                             double[] vars)
Returns the result of evaluating the given math expression. An expression can be a double or int number, or a full expression using ()+-/*?<>. Variables are included as @x1, etc.. The given variable values list is 0 based, so @x1 = vars[0]. Variable @xx will refer to current computed value. Rounds the result to a long Throws an exception on any parsing error

Parameters:
formula - a full math expression string
vars - the 0 based variables
Returns:
the result of the expression

parseIntExpression

public static final int parseIntExpression(java.lang.String formula)
                                    throws java.lang.ArithmeticException
Returns the result of evaluating the given math expression. An expression can be a double or int number, or a full expression using ()+-/*?<>. Variable @xx will refer to current computed value. Rounds the result to an integer. Throws an exception on any parsing error

Parameters:
formula - a full math expression string
Returns:
the result of the expression
Throws:
java.lang.ArithmeticException

parseIntExpression

public static final int parseIntExpression(java.lang.String formula,
                                           double[] vars)
                                    throws java.lang.ArithmeticException
Returns the result of evaluating the given math expression. An expression can be a double or int number, or a full expression using ()+-/*?<>. Variables are included as @x1, etc.. The given variable values list is 0 based, so @x1 = vars[0]. Variable @xx will refer to current computed value. Rounds the result to an integer. Throws an exception on any parsing error

Parameters:
formula - a full math expression string
vars - the 0 based variables
Returns:
the result of the expression
Throws:
java.lang.ArithmeticException

parseMathExpression

public static final double parseMathExpression(java.lang.String formula)
                                        throws java.lang.ArithmeticException
Returns the result of evaluating the given math expression. An expression can be a double or int number, or a full expression using ()+-/*?<>. Variable @xx will refer to current computed value. Throws an exception on any parsing error

Parameters:
formula - a full math expression string
Returns:
the result of the expression
Throws:
java.lang.ArithmeticException

parseMathExpression

public static final double parseMathExpression(java.lang.String formula,
                                               double[] vars)
                                        throws java.lang.ArithmeticException
Returns the result of evaluating the given math expression. An expression can be a double or int number, or a full expression using ()+-/*?<>. Variables are included as @x1, etc.. The given variable values list is 0 based, so @x1 = vars[0]. Variable @xx will refer to current computed value. Throws an exception on any parsing error

Parameters:
formula - a full math expression string
vars - the 0 based variables
Returns:
the result of the expression
Throws:
java.lang.ArithmeticException

s_long

public static final 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"));

Parameters:
LONG - String to convert
Returns:
long Long value of the string

s_float

public static final 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"));

Parameters:
FLOAT - String to convert
Returns:
Float value of the string

s_double

public static final 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"));

Parameters:
DOUBLE - String to convert
Returns:
double Double value of the string

abs

public static final int abs(int val)
Returns the absolute value (X>=0) of the given number

Parameters:
val - the number
Returns:
the absolute value of the number

bitNumber

public static final int bitNumber(long mask)
Returns the first set bit number of the bitmask given

Parameters:
mask - the bit mask given.
Returns:
the first set bit number of the bitmask given

abs

public static final long abs(long val)
Returns the absolute value (X>=0) of the given number

Parameters:
val - the number
Returns:
the absolute value of the number

s_bool

public static final boolean s_bool(java.lang.String BOOL)
Returns the boolean value of a string without crashing

Usage: int num=s_bool(CMD.substring(14));

Parameters:
BOOL - Boolean value of string
Returns:
int Boolean value of the string

isBool

public static final boolean isBool(java.lang.String BOOL)
Returns whether the given string is a boolean value

Usage: if(isBool(CMD.substring(14)));

Parameters:
BOOL - Boolean value of string
Returns:
whether it is a boolean

s_int

public static final int s_int(java.lang.String INT)
Returns the integer value of a string without crashing

Usage: int num=s_int(CMD.substring(14));

Parameters:
INT - Integer value of string
Returns:
int Integer value of the string

s_short

public static final short s_short(java.lang.String SHORT)
Returns the short value of a string without crashing

Usage: int num=s_short(CMD.substring(14));

Parameters:
SHORT - Short value of string
Returns:
short Short value of the string

isLong

public static final boolean isLong(java.lang.String LONG)
Returns whether the given string is a long value

Usage: if(isLong(CMD.substring(14)));

Parameters:
LONG - Long value of string
Returns:
whether it is a long

isInteger

public static final boolean isInteger(java.lang.String INT)
Returns whether the given string is a int value

Usage: if(isInteger(CMD.substring(14)));

Parameters:
INT - Integer value of string
Returns:
whether it is a int

isFloat

public static final boolean isFloat(java.lang.String DBL)
Returns whether the given string is a float value

Usage: if(isFloat(CMD.substring(14)));

Parameters:
DBL - float value of string
Returns:
whether it is a float

s_parseBitIntExpression

public static final 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.

Usage: if(s_parseBitIntExpression(CMDS,CMD.substring(14)));

Parameters:
bits - the ordered string values from 0-whatever.
val - the expression, or list of string values
Returns:
the int value, or 0

s_parseBitLongExpression

public static final 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.

Usage: if(s_parseBitLongExpression(CMDS,CMD.substring(14)));

Parameters:
bits - the ordered string values from 0-whatever.
val - the expression, or list of string values
Returns:
the long value, or 0

setRand

public static final void setRand(java.util.Random rand)
Replaces the internal Random object with the one passed in. Intended to be used for debugging purposes only.

Parameters:
rand - the random object to use

s_parseListLongExpression

public static final 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.

Usage: if(s_parseListLongExpression(CMDS,CMD.substring(14)));

Parameters:
descs - the ordered string values from 0-whatever.
val - the expression, or list of string values
Returns:
the long value, or 0

s_parseListIntExpression

public static final 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.

Usage: if(s_parseListIntExpression(CMDS,CMD.substring(14)));

Parameters:
descs - the ordered string values from 0-whatever.
val - the expression, or list of string values
Returns:
the int value, or 0

isDouble

public static final boolean isDouble(java.lang.String DBL)
Returns whether the given string is a double value

Usage: if(isDouble(CMD.substring(14)));

Parameters:
DBL - double value of string
Returns:
whether it is a double

round

public static final long round(double d)
Parameters:
d - the real number
Returns:
the rounded number as a long
See Also:
Math.round(double)

round

public static final long round(float d)
Parameters:
d - the real number
Returns:
the rounded number as a long
See Also:
Math.round(float)

abs

public static final double abs(double d)
Parameters:
d - the real number
Returns:
the absolute value of the number
See Also:
Math.abs(double)

abs

public static final float abs(float d)
Parameters:
d - the real number
Returns:
the absolute value of the number
See Also:
Math.abs(float)

random

public static final double random()
Returns:
a random number
See Also:
Math.random()

floor

public static final double floor(double d)
Parameters:
d - the number to get the floor of
Returns:
the floor of the given number
See Also:
Math.floor(double), ceiling(double)

floor

public static final float floor(float d)
Parameters:
d - the number to get the floor of
Returns:
the floor of the given number
See Also:
Math.floor(double), ceiling(double)

ceiling

public static final double ceiling(double d)
Parameters:
d - the number to get the ceiling of
Returns:
the ceiling of the given number
See Also:
Math.ceil(double), floor(double)

ceiling

public static final float ceiling(float d)
Parameters:
d - the number to get the ceiling of
Returns:
the ceiling of the given number
See Also:
Math.ceil(double), floor(float)

sqrt

public static final double sqrt(double d)
Parameters:
d - the number to get the square root of
Returns:
the square root of the given number
See Also:
Math.sqrt(double)

sqrt

public static final float sqrt(float d)
Parameters:
d - the number to get the square root of
Returns:
the square root of the given number
See Also:
Math.sqrt(double)

greater

public static final double greater(double a,
                                   double b)
Returns greater of two numbers

Parameters:
a - first number
b - second number
Returns:
greater of the two