org.fixbin
Class FixBin

java.lang.Object
  extended byorg.fixbin.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 FixBin E
           
static long E_f
           
static long FIFTH
           
static long NUM105_3456
           
static long NUM15_336
           
static long NUM3_40
           
static long ONE
           
static FixBin PI
           
static long PI_f
           
static FixBin PI2
           
static long PI2_f
           
protected static long sinHelp1
          Calculates the sin of a given fixbin-encoded value
protected static long sinHelp2
           
 
Constructor Summary
FixBin()
          create a new instance of FixBin with value 0.0
FixBin(FixBin init)
          Create a new instance of FixBin with the same value as another FixBin object
FixBin(int init)
          Create a new instance of FixBin with a given integer value
FixBin(long init)
          Create a new instance of FixBin with a given long value
FixBin(java.lang.String init)
          Create a new instance of FixBin with a String as initializer.
 
Method Summary
 FixBin abs()
          Turns this object into its absolute (non-negative) value
static long abs(long val)
          Returns the absolute value of a fixbin-encoded val
 FixBin add(FixBin other)
          Add another fixbin object to this object
 FixBin add(int other)
          Add an integer to this object
 FixBin add(long other)
          Add a long value to this object
static long add(long x, long y)
          adds two fixbin-values
 FixBin arccos()
          Calculates the arccos of the current object
static long arccos(long val)
          Calculates the arccos of the given fixbin-encoded val
 FixBin arccot()
          Calculates the arccot of the current object
static long arccot(long val)
          Calculates the arccot of the given fixbin-encoded val
 FixBin arcsin()
          Calculates the arcsin of the current object
static long arcsin(long val)
          Calculates the arcsin of the given fixbin-encoded val UPDATED: modification by Petr Kuhlheim
 FixBin arctan()
          Calculates the arctan of the current object
static long arctan(long val)
          Calculates the arctan of the given fixbin-encoded val UPDATED: modification by Petr Kuhlheim
 FixBin clone()
          creates a new Instance of FixBin with the same content.
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
 FixBin cos()
          Calculates the cosinus of the current object
static long cos(long val)
           
 FixBin cot()
          Calculates the cotangens of the current object
static long cot(long val)
          Calculates the cotangens of the given fixbin-encoded val
 FixBin diff(FixBin other)
          Returns the difference (as absolute value) between this and another FixBin-object
 FixBin div(FixBin other)
          Divide current object by another fixbin object
 FixBin div(int other)
          Divide current object by an int value
 FixBin div(long other)
          Divide current object by a long int value
static long div(long val1, long val2)
          Divide two fixbin-encoded values
 boolean equals(java.lang.Object other)
          Checks, wether this object is equal to another object
 FixBin exp()
          Calculates e to the power of the current object
static long exp(long val)
          Calculates e^val val should be fixbin encoded
 java.lang.String format(int decimals)
          returns the content of the object-instance as a String with a given number of digits after the decimal point
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
 boolean greaterEqual(FixBin other)
          Checks, wether this object is greater than or equal to another object
 boolean greaterThan(FixBin other)
          Checks, wether this object is greater than another object
 int intValue()
          Returns the integer-value of the current object
static int intValue(long val)
          Returns the integer-value of a given fixbin-encoded val
 boolean lessEqual(FixBin other)
          Checks, wether this object is less than or equal to another object
 boolean lessThan(FixBin other)
          Checks, wether this object is less than another object
 FixBin ln()
          Calculates the natural log of the current object
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
 long longValue()
          Returns the long-value of the current object
static long longValue(long val)
          Returns the long-value of a given fixbin-encoded val
 FixBin mul(FixBin other)
          Multiply another FixBin with this object
 FixBin mul(int other)
          Multiply this object with an integer value
 FixBin mul(long other)
          Multiply this object with a long int value
static long mul(long val1, long val2)
          Multiply two fixbin encoded values
 FixBin pow(FixBin exp)
          Calculate the current object's value by the power of the given Fixbin object.
 FixBin pow(int howmany)
          Calculate the current object's value by the power if the given integer value
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.
 void setRawData(long value)
          sets the "raw" long (fixbin-coded) value
 FixBin sin()
          Calculates the sin of the current object
static long sin(long val)
           
static long sqr(long x)
          Calculate the square of the given fixbin-encoded value
 FixBin sqrt()
          Calculates the square root of the current object
 FixBin sqrt(int nth)
          Calculates the nth root of the current object
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
 FixBin sub(FixBin other)
          Substract another fixbin object from this object
 FixBin sub(int other)
          Substract an integer value from the current Object
 FixBin sub(long other)
          Substract a long int value from the current Object
static long sub(long x, long y)
          Substract two fixbin-coded values
 FixBin tan()
          Calculates the tangens of the current object
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
 java.lang.String toString()
          returns the content of the object-instance as a String
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
finalize, getClass, hashCode, notify, notifyAll, 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

public static FixBin PI

E

public static FixBin E

PI2

public static FixBin PI2

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()
create a new instance of FixBin with value 0.0


FixBin

public FixBin(int init)
Create a new instance of FixBin with a given integer value

Parameters:
init - (int)

FixBin

public FixBin(long init)
Create a new instance of FixBin with a given long value

Parameters:
init - (long)

FixBin

public FixBin(FixBin init)
Create a new instance of FixBin with the same value as another FixBin object

Parameters:
init - (org.fixbin.FixBin)

FixBin

public FixBin(java.lang.String init)
Create a new instance of FixBin with a String as initializer. The String must be coded to represent a floating-point number. Both, dot and comma are accepted as decimal point, but a decimal point must only appear once. Also, no other characters than '-' (must only appear once and at the beginning) or '0' to '9' are allowed.

Parameters:
init - (String)
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

setRawData

public void setRawData(long value)
sets the "raw" long (fixbin-coded) value

Parameters:
value - (long)

clone

public FixBin clone()
creates a new Instance of FixBin with the same content.

Returns:
FixBin

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

format

public java.lang.String format(int decimals)
returns the content of the object-instance as a String with a given number of digits after the decimal point

Parameters:
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

toString

public java.lang.String toString()
returns the content of the object-instance as a String

Returns:
String

add

public FixBin add(FixBin other)
Add another fixbin object to this object

Parameters:
other - (FixBin)
Returns:
this (FixBin)

add

public FixBin add(int other)
Add an integer to this object

Parameters:
other - (int)
Returns:
this

add

public FixBin add(long other)
Add a long value to this object

Parameters:
other - (long)
Returns:
this

add

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

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

sub

public FixBin sub(FixBin other)
Substract another fixbin object from this object

Parameters:
other - (FixBin)
Returns:
this

sub

public FixBin sub(int other)
Substract an integer value from the current Object

Parameters:
other - (int)
Returns:
this

sub

public FixBin sub(long other)
Substract a long int value from the current Object

Parameters:
other - (long)
Returns:
this

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 FixBin mul(FixBin other)
Multiply another FixBin with this object

Parameters:
other - (FixBin)
Returns:
this

mul

public FixBin mul(int other)
Multiply this object with an integer value

Parameters:
other - (int)
Returns:
this

mul

public FixBin mul(long other)
Multiply this object with a long int value

Parameters:
other - (long)
Returns:
this

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 FixBin div(FixBin other)
Divide current object by another fixbin object

Parameters:
other - (FixBin)
Returns:
this

div

public FixBin div(int other)
Divide current object by an int value

Parameters:
other - (int)
Returns:
this

div

public FixBin div(long other)
Divide current object by a long int value

Parameters:
other - (long)
Returns:
this

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 FixBin pow(int howmany)
Calculate the current object's value by the power if the given integer value

Parameters:
howmany - (int)

pow

public FixBin pow(FixBin exp)
           throws java.lang.Exception
Calculate the current object's value by the power of the given Fixbin object.

Parameters:
exp - (FixBin)
Returns:
this^exp (FixBin)
Throws:
java.lang.Exception

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 FixBin sqrt()
            throws java.lang.Exception
Calculates the square root of the current object

Returns:
this
Throws:
java.lang.Exception

sqrt

public FixBin sqrt(int nth)
            throws java.lang.Exception
Calculates the nth root of the current object

Parameters:
nth - (int)
Returns:
this (^(1/nth))
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 FixBin exp()
           throws java.lang.Exception
Calculates e to the power of the current object

Returns:
e^this
Throws:
java.lang.Exception

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

ln

public FixBin ln()
          throws java.lang.Exception
Calculates the natural log of the current object

Returns:
ln(this)
Throws:
java.lang.Exception

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 FixBin sin()
           throws java.lang.Exception
Calculates the sin of the current object

Returns:
sin(this)
Throws:
java.lang.Exception

sin

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

cos

public FixBin cos()
           throws java.lang.Exception
Calculates the cosinus of the current object

Returns:
cos(this)
Throws:
java.lang.Exception

cos

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

tan

public FixBin tan()
           throws java.lang.Exception
Calculates the tangens of the current object

Returns:
tan(this)
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 FixBin cot()
           throws java.lang.Exception
Calculates the cotangens of the current object

Returns:
cot(this)
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 FixBin arcsin()
              throws java.lang.Exception
Calculates the arcsin of the current object

Returns:
arcsin(this)
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 FixBin arccos()
              throws java.lang.Exception
Calculates the arccos of the current object

Returns:
arccos(this)
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 FixBin arctan()
              throws java.lang.Exception
Calculates the arctan of the current object

Returns:
arctan(this)
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 FixBin arccot()
              throws java.lang.Exception
Calculates the arccot of the current object

Returns:
arccot(this)
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 int intValue()
Returns the integer-value of the current object

Returns:
(int)

intValue

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

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

longValue

public long longValue()
Returns the long-value of the current object

Returns:
(long)

longValue

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

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

greaterThan

public boolean greaterThan(FixBin other)
Checks, wether this object is greater than another object

Returns:
boolean

lessThan

public boolean lessThan(FixBin other)
Checks, wether this object is less than another object

Returns:
boolean

equals

public boolean equals(java.lang.Object other)
Checks, wether this object is equal to another object

Returns:
boolean

greaterEqual

public boolean greaterEqual(FixBin other)
Checks, wether this object is greater than or equal to another object

Returns:
boolean

lessEqual

public boolean lessEqual(FixBin other)
Checks, wether this object is less than or equal to another object

Returns:
boolean

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 FixBin abs()
Turns this object into its absolute (non-negative) value

Returns:
abs(this)

abs

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

Returns:
abs(val)

diff

public FixBin diff(FixBin other)
Returns the difference (as absolute value) between this and another FixBin-object

Parameters:
other - (FixBin)
Returns:
abs(this-other)