danger.util
Class Fixed

java.lang.Object
  extended by danger.util.Fixed


public class Fixed
extends Object

Fixed point math library. Precision is 16 bits whole, 16 bits fractional. Uses 32 bit values to represent the Fixed number.


Field Summary
static int FIXED_ONE
           
static int FIXED_ONE_HALF
           
static int FIXED_PI
           
static int FIXED_TWO
           
static int MAX_VALUE
           
 
Constructor Summary
Fixed()
           
 
Method Summary
static int abs(int value)
          return absolute value of a fixed point number
static int add(int fvalue1, int fvalue2)
          add two fixed point values together
static int cos(int angle)
          angle = 0-359 degrees.
static int cosf(int fAngle)
          fAngle = 0-359 in fixed point.
static int divide(int dividend, int divisor)
          divide a fixed point value by a fixed point value dividend - number to divide "into" divisor - number to divide "by" If divisor is 0 (zero), then an ArithmeticException is thrown.
static int floor(int fValue)
          Given a signed fixed point value, and return the nearest integer.
static int fromInt(int value)
          given an integer value, return a fixed point value
static int fromReal(int whole, int dividend, int divisor)
          create fixed point value from real expression.
static int getFraction(int fValue)
          given a fixed point value, return the fraction part
static int hypot(int x, int y)
          Returns sqrt(x**2 + y**2), the hypotenuse of a right-angled triangle with sides x and y.
static int multiply(int factor1, int factor2)
          sign multiply two fixed point values together and return a fixed point value reference - http://www.embedded.com/2001/0104/0104feat1list2.htm
static int round(int fValue)
          Round to nearest fixed point value.
static int sin(int angle)
          angle = 0-359 degrees.
static int sinf(int fAngle)
          fAngle = 0-359 in fixed point.
static int sqrt(int fValue)
          Returns square root of fixed value Throws Arithmetic Exception if (fValue < 0) This is not accurate, but faster than Math.sqrt()
static int subtract(int fvalue1, int fvalue2)
          subtract two fixed point values
 void testCosSin()
          Deprecated. For internal use only.
static void testSqrt()
          Deprecated. For internal use only.
static int toInt(int fvalue)
          given a fixed point value, return an integer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FIXED_ONE

public static final int FIXED_ONE
See Also:
Constant Field Values

FIXED_TWO

public static final int FIXED_TWO
See Also:
Constant Field Values

FIXED_PI

public static final int FIXED_PI
See Also:
Constant Field Values

MAX_VALUE

public static final int MAX_VALUE
See Also:
Constant Field Values

FIXED_ONE_HALF

public static final int FIXED_ONE_HALF
See Also:
Constant Field Values
Constructor Detail

Fixed

public Fixed()
Method Detail

fromInt

public static int fromInt(int value)
given an integer value, return a fixed point value


toInt

public static int toInt(int fvalue)
given a fixed point value, return an integer


getFraction

public static int getFraction(int fValue)
given a fixed point value, return the fraction part


fromReal

public static int fromReal(int whole,
                           int dividend,
                           int divisor)
create fixed point value from real expression. ie. 5 3/4 would be 5, 3, 4 pi 3.14 would be 0, 22, 7


abs

public static int abs(int value)
return absolute value of a fixed point number


divide

public static int divide(int dividend,
                         int divisor)
divide a fixed point value by a fixed point value dividend - number to divide "into" divisor - number to divide "by" If divisor is 0 (zero), then an ArithmeticException is thrown.


add

public static int add(int fvalue1,
                      int fvalue2)
add two fixed point values together


subtract

public static int subtract(int fvalue1,
                           int fvalue2)
subtract two fixed point values


multiply

public static int multiply(int factor1,
                           int factor2)
sign multiply two fixed point values together and return a fixed point value reference - http://www.embedded.com/2001/0104/0104feat1list2.htm


sinf

public static int sinf(int fAngle)
fAngle = 0-359 in fixed point. Returns 16.16 value


cosf

public static int cosf(int fAngle)
fAngle = 0-359 in fixed point. Returns 16.16 value


sin

public static int sin(int angle)
angle = 0-359 degrees. Returns 16.16 value


cos

public static int cos(int angle)
angle = 0-359 degrees. Returns 16.16 value


floor

public static int floor(int fValue)
Given a signed fixed point value, and return the nearest integer. Returns an integer.


round

public static int round(int fValue)
Round to nearest fixed point value. Returns a fixed value


hypot

public static int hypot(int x,
                        int y)
Returns sqrt(x**2 + y**2), the hypotenuse of a right-angled triangle with sides x and y. hypot(3<<16, 4<<16) => 5<<16 Throws IllegalArgumentException if ((x|y) < 0) || (x > 0x800000) || (y > 0x800000)


sqrt

public static int sqrt(int fValue)
Returns square root of fixed value Throws Arithmetic Exception if (fValue < 0) This is not accurate, but faster than Math.sqrt()


testCosSin

public void testCosSin()
Deprecated. For internal use only.


testSqrt

public static void testSqrt()
Deprecated. For internal use only.