org.fixbin.light
Class FixBin

java.lang.Object
  extended byorg.fixbin.light.FixBin

public class FixBin
extends java.lang.Object

FixBin the light version of the FixBin library this class can be used in 2 ways: either the static methods are used or alternatively it can be used to instantiate objects that handle the values (much like the StringBuffer class). Example 1: FixBin myVal = new FixBin("1.234"); myVal.mul(3); System.out.println("Result: " + myVal); Example 2: long myVal = FixBin-toFixBin("1.234"); long val3 = FixBin.toFixBin("3"); myVal = FixBin.mul(myVal, val3); System.out.println("Result: " + FixBin.toString(myVal));


Field Summary
protected static int commaBitPos
           
protected static long commaBitVal
           
protected static long cosHelp1
          Calculates the cosinus of the given fixbin-encoded val
protected static long cosHelp2
           
static long E_f
           
static long FIFTH
           
static long NUM105_3456
           
static long NUM15_336
           
static long NUM3_40
           
static long ONE
           
static long PI_f
           
static long PI2_f
           
protected static long sinHelp1
          Calculates the sin of a given fixbin-encoded value
protected static long sinHelp2
           
 
Constructor Summary
FixBin()
           
 
Method Summary
static long abs(long val)
          Returns the absolute value of a fixbin-encoded val
static long add(long x, long y)
          adds two fixbin-values
static long arccos(long val)
          Calculates the arccos of the given fixbin-encoded val
static long arccot(long val)
          Calculates the arccot of the given fixbin-encoded val
static long arcsin(long val)
          Calculates the arcsin of the given fixbin-encoded val UPDATED: modification by Petr Kuhlheim
static long arctan(long val)
          Calculates the arctan of the given fixbin-encoded val UPDATED: modification by Petr Kuhlheim
static int compareTo(long x, long y)
          Compares two (fixbin-encoded) values and returns 1 if x > y, -1 if x < y, 0 if x == y
static long cos(long val)
           
static long cot(long val)
          Calculates the cotangens of the given fixbin-encoded val
static long div(long val1, long val2)
          Divide two fixbin-encoded values
static long exp(long val)
          Calculates e^val val should be fixbin encoded
static java.lang.String format(long fixVal, int decimals)
          formats a fixbin-coded value to a String with a given number of figures after the decimal point
static int intValue(long val)
          Returns the integer-value of a given fixbin-encoded val
static long ln(long val)
          Calculates the natural log of the given fixbin-encoded val
protected static long lngt1(long val)
          Calculates the natural log for values > 1
protected static long lnlt1(long val)
          Calculates the natural log for values < 1
static long longValue(long val)
          Returns the long-value of a given fixbin-encoded val
static long mul(long val1, long val2)
          Multiply two fixbin encoded values
static long pow(long x, int howmany)
          Calculates the power of the first parameter by the second.
static long pow(long bas, long exp)
          Calculates the power of the first parameter by the second.
static long quickdiv(long val1, long val2)
          Method to quickly divide two fixbin values.
static long quickmul(long val1, long val2)
          Method to quickly multiply two Fixbin values.
static long sin(long val)
           
static long sqr(long x)
          Calculate the square of the given fixbin-encoded value
static long sqrt(long val)
          Calculates the square root of the given fixbin-encoded value
static long sqrt(long val, int nth)
          Calculates the nth root of the given value (val). val should be fixbin-encoded, nth is just an integer value
static long sub(long x, long y)
          Substract two fixbin-coded values
static long tan(long val)
          Calculates the tangens of the given fixbin-encoded val
static long toFixBin(int val)
          Transform an integer to a FixBin coded long
static long toFixBin(long val)
          Transform a long value to a FixBin coded long
static long toFixBin(java.lang.String init)
          Transform a String into a fixbin-coded LONG
static java.lang.String toString(long fixVal)
          returns the value of the fixbin-coded value as a String
protected static long xbyndivnfact(long x, int n)
          This is a helper method required by other exponential methods it calculates x ^ n / n!
protected static long xmmbyndivnxppbynx2(long x, int n)
          calculates an intermediate value for ln
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

commaBitPos

protected static final int commaBitPos
See Also:
Constant Field Values

commaBitVal

protected static final long commaBitVal
See Also:
Constant Field Values

PI_f

public static long PI_f

E_f

public static long E_f

PI2_f

public static long PI2_f

ONE

public static long ONE

FIFTH

public static long FIFTH

NUM3_40

public static long NUM3_40

NUM15_336

public static long NUM15_336

NUM105_3456

public static long NUM105_3456

sinHelp1

protected static long sinHelp1
Calculates the sin of a given fixbin-encoded value


sinHelp2

protected static long sinHelp2

cosHelp1

protected static long cosHelp1
Calculates the cosinus of the given fixbin-encoded val


cosHelp2

protected static long cosHelp2
Constructor Detail

FixBin

public FixBin()
Method Detail

toFixBin

public static long toFixBin(java.lang.String init)
Transform a String into a fixbin-coded LONG

Parameters:
init - (String)
Returns:
long

toFixBin

public static long toFixBin(int val)
Transform an integer to a FixBin coded long

Parameters:
val - (int)
Returns:
long

toFixBin

public static long toFixBin(long val)
Transform a long value to a FixBin coded long

Parameters:
val - (long)
Returns:
long

format

public static java.lang.String format(long fixVal,
                                      int decimals)
formats a fixbin-coded value to a String with a given number of figures after the decimal point

Parameters:
fixVal - (long)
decimals - (int)
Returns:
String

toString

public static java.lang.String toString(long fixVal)
returns the value of the fixbin-coded value as a String

Parameters:
fixVal - (long)
Returns:
String

add

public static long add(long x,
                       long y)
adds two fixbin-values

Parameters:
x - (long)
y - (long)
Returns:
x+y (long)

sub

public static long sub(long x,
                       long y)
Substract two fixbin-coded values

Parameters:
x - (long)
y - (long)
Returns:
x-y (long)

mul

public static long mul(long val1,
                       long val2)
Multiply two fixbin encoded values

Parameters:
val1 - (long)
val2 - (long)
Returns:
val1 * val2 (long)

quickmul

public static long quickmul(long val1,
                            long val2)
Method to quickly multiply two Fixbin values. This method can be used when the multiplication doesn't need to be overflow-safe (see static mul above), but when performance is an issue.

Parameters:
val1 - (long) the first operand
val2 - (long) the second operand
Returns:
a fixbin-encoded result of val1 * val2
Since:
0.4

div

public static long div(long val1,
                       long val2)
Divide two fixbin-encoded values

Parameters:
val1 - (long)
val2 - (long)
Returns:
val1 / val2 (long)

quickdiv

public static long quickdiv(long val1,
                            long val2)
Method to quickly divide two fixbin values. This method is NOT overflow- safe (see above) and should be used only if performance is critical

Parameters:
val1 - (long) the dividend
val2 - (long) the divisor
Returns:
the fixbin encoded result of val1 / val2
Since:
0.4

sqr

public static long sqr(long x)
Calculate the square of the given fixbin-encoded value

Parameters:
x - (long)
Returns:
x^2 (long)

pow

public static long pow(long x,
                       int howmany)
Calculates the power of the first parameter by the second. All values except howmany should of course be fixbin-encoded

Parameters:
x - (long)
howmany - (int)
Returns:
x^howmany

pow

public static long pow(long bas,
                       long exp)
                throws java.lang.Exception
Calculates the power of the first parameter by the second. All values should of course be fixbin-encoded

Returns:
x^y (long)
Throws:
java.lang.Exception

sqrt

public static long sqrt(long val)
                 throws java.lang.Exception
Calculates the square root of the given fixbin-encoded value

Parameters:
val - (long)
Returns:
sqrt(val) (long)
Throws:
java.lang.Exception

sqrt

public static long sqrt(long val,
                        int nth)
                 throws java.lang.Exception
Calculates the nth root of the given value (val). val should be fixbin-encoded, nth is just an integer value

Parameters:
val - (long)
nth - (int)
Returns:
val ^ (1/nth) (long)
Throws:
java.lang.Exception

xbyndivnfact

protected static long xbyndivnfact(long x,
                                   int n)
This is a helper method required by other exponential methods it calculates x ^ n / n!

Parameters:
x - (long)
n - (int)
Returns:
long

exp

public static long exp(long val)
                throws java.lang.Exception
Calculates e^val val should be fixbin encoded

Parameters:
val - (long)
Returns:
e^val (long)
Throws:
java.lang.Exception

xmmbyndivnxppbynx2

protected static long xmmbyndivnxppbynx2(long x,
                                         int n)
calculates an intermediate value for ln

Parameters:
x - (long)
n - (int)
Returns:
long

lngt1

protected static long lngt1(long val)
                     throws java.lang.Exception
Calculates the natural log for values > 1

Parameters:
val - (long)
Returns:
ln(val) (long)
Throws:
java.lang.Exception

lnlt1

protected static long lnlt1(long val)
                     throws java.lang.Exception
Calculates the natural log for values < 1

Parameters:
val - (long)
Returns:
ln(this) (long)
Throws:
java.lang.Exception

ln

public static long ln(long val)
               throws java.lang.Exception
Calculates the natural log of the given fixbin-encoded val

Parameters:
val - (long)
Returns:
ln(val) (long)
Throws:
java.lang.Exception

sin

public static long sin(long val)
                throws java.lang.Exception
Throws:
java.lang.Exception

cos

public static long cos(long val)
                throws java.lang.Exception
Throws:
java.lang.Exception

tan

public static long tan(long val)
                throws java.lang.Exception
Calculates the tangens of the given fixbin-encoded val

Parameters:
val - (long)
Returns:
tan(val) (long)
Throws:
java.lang.Exception

cot

public static long cot(long val)
                throws java.lang.Exception
Calculates the cotangens of the given fixbin-encoded val

Parameters:
val - (long)
Returns:
cot(val) (long)
Throws:
java.lang.Exception

arcsin

public static long arcsin(long val)
                   throws java.lang.Exception
Calculates the arcsin of the given fixbin-encoded val UPDATED: modification by Petr Kuhlheim

Parameters:
val - (long)
Returns:
arcsin(val) (long)
Throws:
java.lang.Exception

arccos

public static long arccos(long val)
                   throws java.lang.Exception
Calculates the arccos of the given fixbin-encoded val

Parameters:
val - (long)
Returns:
arccos(val) (long)
Throws:
java.lang.Exception

arctan

public static long arctan(long val)
                   throws java.lang.Exception
Calculates the arctan of the given fixbin-encoded val UPDATED: modification by Petr Kuhlheim

Parameters:
val - (long)
Returns:
arctan(val) (long)
Throws:
java.lang.Exception

arccot

public static long arccot(long val)
                   throws java.lang.Exception
Calculates the arccot of the given fixbin-encoded val

Parameters:
val - (long)
Returns:
arccot(val) (long)
Throws:
java.lang.Exception

intValue

public static int intValue(long val)
Returns the integer-value of a given fixbin-encoded val

Parameters:
val - (long)
Returns:
(int)

longValue

public static long longValue(long val)
Returns the long-value of a given fixbin-encoded val

Parameters:
val - (long)
Returns:
(long)

compareTo

public static int compareTo(long x,
                            long y)
Compares two (fixbin-encoded) values and returns 1 if x > y, -1 if x < y, 0 if x == y

Parameters:
x - (long)
y - (long)
Returns:
int

abs

public static long abs(long val)
Returns the absolute value of a fixbin-encoded val

Returns:
abs(val)