All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class berkeley.cs.dmc.rapid2d.FixedPt

java.lang.Object
   |
   +----berkeley.cs.dmc.rapid2d.FixedPt

public final class FixedPt
extends Object

The FixedPt is a class for doing fixed point arithmetic. It is NOT a class for fixed point numbers. The actual fixed point numbers are stored in integers and add, subtracted, multiplied, etc... using the routines of the fixed point. This may lead to confusion between integers and fixed point values, but um... deal with it.

int a, b;
a = FixedPt.toFixed( 100 );
b = FixedPt.toFixed( 1.25 );
System.out.println( "100 * 1.25 = " + FixedPt.toString( FixedPt.mul( a, b ) ) );


Variable Index

 o fractMask
 o HALF
Fixed point for 0.5.
 o intMask
 o ONE
Fixed point for 1.
 o SHIFT
 o ZERO
Fixed point for 0.

Constructor Index

 o FixedPt()

Method Index

 o abs(int)
 o acos(int)
 o add(int, int)
Adds two fixed point values.
 o asin(int)
 o atan(int)
 o atan2(int, int)
 o ceil(int)
Rounds a fixed point value to the largest integer less than or equal.
 o cos(int)
 o div(int, int)
Divides two fixed point values
 o divByInt(int, int)
Divides a fixed point value by an integer
 o exp(int)
 o floor(int)
Rounds a fixed point value to the smallest integer greater than or equal.
 o fract(int)
Returns the fractional potion of a fixed point value.
 o log(int)
 o max(int, int)
 o min(int, int)
 o mul(int, int)
Multiplies two fixed point values
 o neg(int)
Negates a fixed point value.
 o pow(int, int)
 o round(int)
Rounds a fixed point value to the nearest integer
 o sin(int)
 o sqrt(int)
Returns the square root of an integer.
 o sub(int, int)
Subtracts two fixed point values.
 o tan(int)
 o toDouble(int)
Returns a double representation of a fixed point value
 o toFixed(double)
Converts a double to a fixed point value.
 o toFixed(float)
Converts a float to a fixed point value.
 o toFixed(int)
Converts an integer to a fixed point value.
 o toFloat(int)
Returns a floating point representation of a fixed point value
 o toString(int)
Returns a string of the form "1 23/256" where 1 is the integer part, 23 is the fractional part, and 256 is the denominator.
 o trunc(int)
Truncates a fixed point value to an integer.

Variables

 o SHIFT
 public static final int SHIFT
 o ONE
 public static final int ONE
Fixed point for 1. Equivalent to toFixed(1)

 o ZERO
 public static final int ZERO
Fixed point for 0. Equivalent to toFixed(0)

 o HALF
 public static final int HALF
Fixed point for 0.5. Equivalent to toFixed(0.5)

 o fractMask
 public static final int fractMask
 o intMask
 public static final int intMask

Constructors

 o FixedPt
 public FixedPt()

Methods

 o trunc
 public static final int trunc(int a)
Truncates a fixed point value to an integer.

Parameters:
a - fixed point
Returns:
integer
 o round
 public static final int round(int a)
Rounds a fixed point value to the nearest integer

Parameters:
a - fixed point
Returns:
integer
 o fract
 public static final int fract(int a)
Returns the fractional potion of a fixed point value.

Parameters:
a - fixed point
Returns:
fixed point
 o ceil
 public static final int ceil(int a)
Rounds a fixed point value to the largest integer less than or equal.

Parameters:
a - fixed point
Returns:
fixed point
 o floor
 public static final int floor(int a)
Rounds a fixed point value to the smallest integer greater than or equal.

Parameters:
a - fixed point
Returns:
fixed point
 o toFloat
 public static final float toFloat(int a)
Returns a floating point representation of a fixed point value

Parameters:
a - fixed point
Returns:
value as a float
 o toDouble
 public static final double toDouble(int a)
Returns a double representation of a fixed point value

Parameters:
a - fixed point
Returns:
the value as a double
 o toFixed
 public static final int toFixed(int a)
Converts an integer to a fixed point value.

Parameters:
a - integer
Returns:
fixed point
 o toFixed
 public static final int toFixed(float a)
Converts a float to a fixed point value.

Parameters:
a - float
Returns:
fixed point
 o toFixed
 public static final int toFixed(double a)
Converts a double to a fixed point value.

Parameters:
a - double
Returns:
fixed point
 o add
 public static final int add(int a,
                             int b)
Adds two fixed point values. Addition may also be done using the '+' operator on the integers representing fixed points.

Parameters:
a - fixed point
b - fixed point
Returns:
fixed point
 o sub
 public static final int sub(int a,
                             int b)
Subtracts two fixed point values. Subtraction may also be done with the '-' operator.

Parameters:
a - fixed point
b - fixed point
Returns:
fixed point
 o neg
 public static final int neg(int a)
Negates a fixed point value. Negation may also be done with the unary '-' operator.

Parameters:
a - fixed point
Returns:
fixed point
 o mul
 public static final int mul(int a,
                             int b)
Multiplies two fixed point values

Parameters:
a - fixed point
b - fixed point
Returns:
fixed point
 o div
 public static final int div(int n,
                             int d)
Divides two fixed point values

Parameters:
a - fixed point
b - fixed point
Returns:
fixed point
 o divByInt
 public static final int divByInt(int n,
                                  int di)
Divides a fixed point value by an integer

Parameters:
a - fixed point
b - integer
Returns:
fixed point
 o abs
 public static final int abs(int a)
 o acos
 public static final int acos(int a)
 o asin
 public static final int asin(int a)
 o atan
 public static final int atan(int a)
 o atan2
 public static final int atan2(int a,
                               int b)
 o cos
 public static final int cos(int a)
 o exp
 public static final int exp(int a)
 o log
 public static final int log(int a)
 o max
 public static final int max(int a,
                             int b)
 o min
 public static final int min(int a,
                             int b)
 o pow
 public static final int pow(int a,
                             int b)
 o sin
 public static final int sin(int a)
 o tan
 public static final int tan(int a)
 o sqrt
 public static final int sqrt(int a)
Returns the square root of an integer. A negative parameter will cause an ArithmeticException.

Parameters:
a - fixed point
Returns:
the square root (fixed point)
 o toString
 public static final String toString(int a)
Returns a string of the form "1 23/256" where 1 is the integer part, 23 is the fractional part, and 256 is the denominator.

Parameters:
a - FixedPt int value
Returns:
the string representation of the parameter

All Packages  Class Hierarchy  This Package  Previous  Next  Index