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 ) ) );
-
fractMask
-
-
HALF
- Fixed point for 0.5.
-
intMask
-
-
ONE
- Fixed point for 1.
-
SHIFT
-
-
ZERO
- Fixed point for 0.
-
FixedPt()
-
-
abs(int)
-
-
acos(int)
-
-
add(int, int)
- Adds two fixed point values.
-
asin(int)
-
-
atan(int)
-
-
atan2(int, int)
-
-
ceil(int)
- Rounds a fixed point value to the largest integer less than or equal.
-
cos(int)
-
-
div(int, int)
- Divides two fixed point values
-
divByInt(int, int)
- Divides a fixed point value by an integer
-
exp(int)
-
-
floor(int)
- Rounds a fixed point value to the smallest integer greater than or equal.
-
fract(int)
- Returns the fractional potion of a fixed point value.
-
log(int)
-
-
max(int, int)
-
-
min(int, int)
-
-
mul(int, int)
- Multiplies two fixed point values
-
neg(int)
- Negates a fixed point value.
-
pow(int, int)
-
-
round(int)
- Rounds a fixed point value to the nearest integer
-
sin(int)
-
-
sqrt(int)
- Returns the square root of an integer.
-
sub(int, int)
- Subtracts two fixed point values.
-
tan(int)
-
-
toDouble(int)
- Returns a double representation of a fixed point value
-
toFixed(double)
- Converts a double to a fixed point value.
-
toFixed(float)
- Converts a float to a fixed point value.
-
toFixed(int)
- Converts an integer to a fixed point value.
-
toFloat(int)
- Returns a floating point representation of a fixed point value
-
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.
-
trunc(int)
- Truncates a fixed point value to an integer.
SHIFT
public static final int SHIFT
ONE
public static final int ONE
- Fixed point for 1. Equivalent to toFixed(1)
ZERO
public static final int ZERO
- Fixed point for 0. Equivalent to toFixed(0)
HALF
public static final int HALF
- Fixed point for 0.5. Equivalent to toFixed(0.5)
fractMask
public static final int fractMask
intMask
public static final int intMask
FixedPt
public FixedPt()
trunc
public static final int trunc(int a)
- Truncates a fixed point value to an integer.
- Parameters:
- a - fixed point
- Returns:
- integer
round
public static final int round(int a)
- Rounds a fixed point value to the nearest integer
- Parameters:
- a - fixed point
- Returns:
- integer
fract
public static final int fract(int a)
- Returns the fractional potion of a fixed point value.
- Parameters:
- a - fixed point
- Returns:
- fixed point
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
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
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
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
toFixed
public static final int toFixed(int a)
- Converts an integer to a fixed point value.
- Parameters:
- a - integer
- Returns:
- fixed point
toFixed
public static final int toFixed(float a)
- Converts a float to a fixed point value.
- Parameters:
- a - float
- Returns:
- fixed point
toFixed
public static final int toFixed(double a)
- Converts a double to a fixed point value.
- Parameters:
- a - double
- Returns:
- fixed point
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
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
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
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
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
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
abs
public static final int abs(int a)
acos
public static final int acos(int a)
asin
public static final int asin(int a)
atan
public static final int atan(int a)
atan2
public static final int atan2(int a,
int b)
cos
public static final int cos(int a)
exp
public static final int exp(int a)
log
public static final int log(int a)
max
public static final int max(int a,
int b)
min
public static final int min(int a,
int b)
pow
public static final int pow(int a,
int b)
sin
public static final int sin(int a)
tan
public static final int tan(int a)
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)
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