|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.vodafone.v10.util.FixedPoint
The FixedPoint class provides functions for fixed-point decimal operations. A FixedPoint object holds a fixed-point value where the 16th bit is next to the decimal. Both the integer part and decimal part have 16-bit resolution. The limit on internal operations is 64 bits (32 bits each for the integer part and decimal part).
The integer argument for the FixedPoint class constructor and addition, subtraction, multiplication and division methods is regarded as a fixed-point value (with bit 16 as the digit next to the decimal point.).
Keep in mind the following points when working with the integer or decimal portion of a FixedPoint object:
With a positive value, the method for getting the integer part, getInteger()
, returns the high 16 bits of the value, while that for getting the decimal part, getDecimal()
, returns the low 16 bits. For the value 1.5, for example, getInteger()
returns 1 and getDecimal()
returns 32768.
In the case of a negative value, both the integer part and decimal part are returned as negative values. For example, if the value is -1.5, the integer part method getInteger()
returns -1, and the decimal part method getDecimal()
returns the result of multiplying -0.5 by 65536 (-32768).
Note that these do not correspond exactly to the fixed decimal point expressions integer part (high 16 bits) and decimal part (low 16 bits). For example, the fixed decimal point expression for -1.5 is -2 for the high 16 bits and +0.5 for the low 16 bits.
Regardless of whether a value is positive or negative, when the value obtained by getInteger()
is raised by 65536 (left-shifted 16 bits) and added to that obtained by getDecimal()
, the result is a fixed decimal point expression with bit 16 as the digit next to the decimal point.
Constructor Summary | |
FixedPoint()
FixedPoint constructor. |
|
FixedPoint(int value)
FixedPoint constructor. |
Method Summary | |
FixedPoint |
acos(FixedPoint v)
Calculates arccos. |
FixedPoint |
add(FixedPoint n)
Performs addition. |
FixedPoint |
add(int n)
Performs addition. |
FixedPoint |
asin(FixedPoint v)
Calculates arcsin. |
FixedPoint |
atan(FixedPoint v)
Calculates arctan. |
FixedPoint |
clone()
Copies an object. |
FixedPoint |
cos(FixedPoint r)
Calculates cos. |
FixedPoint |
divide(FixedPoint n)
Performs division. |
FixedPoint |
divide(int n)
Performs division. |
int |
getDecimal()
Gets the decimal part. |
int |
getInteger()
Gets the integer part. |
static FixedPoint |
getMaximum()
Gets a maximum value. |
static FixedPoint |
getMinimum()
Gets a minimum value. |
static FixedPoint |
getPI()
Gets pi (a circular constant). |
FixedPoint |
inverse()
Calculates an inverse. |
boolean |
isInfinite()
Checks for overflow. |
FixedPoint |
multiply(FixedPoint n)
Performs multiplication. |
FixedPoint |
multiply(int n)
Performs multiplication. |
FixedPoint |
pow()
Calculates a square. |
void |
setValue(int value)
Sets a fixed-point value. |
FixedPoint |
sin(FixedPoint r)
Calculates sin. |
FixedPoint |
sqrt()
Calculates a square root. |
FixedPoint |
subtract(FixedPoint n)
Performs subtraction. |
FixedPoint |
subtract(int n)
Performs subtraction. |
FixedPoint |
tan(FixedPoint r)
Calculates tan. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public FixedPoint()
FixedPoint constructor.
Holds value 0.0.
public FixedPoint(int value)
FixedPoint constructor.
The value parameter holds the integer part in the high 16 bits and the decimal part in the low 16 bits.
value
- The held fixed-point valueMethod Detail |
public int getInteger()
Gets the integer part.
If the number is positive, returns the high 16 bits of a fixed-point value. If the number is negative, returns a value derived by inverting the sign, discarding to the right of the decimal point, then sign-extending the high 16 bits of the sign-inverted result. For -1.5, -1 (0xFFFFFFFF) would be returned.
public int getDecimal()
Gets the decimal part.
If the number is positive, returns the low 16 bits of a fixed-point value. If the number is negative, returns a value derived by inverting the sign, treating the integer part as 0, then sign-extending the low 16 bits of the sign-inverted result. For -1.5, the low 16 bits of -0.5 would be sign-extended and returned as -32768 (0xFFFF8000).
public void setValue(int value)
Sets a fixed-point value.
Holds the high 16 bits of the value parameter as the integer part, and the low 16 bits as the decimal part.
value
- New fixed-point value (an integer obtained by multiplying a decimal value by 65536)public FixedPoint add(FixedPoint n)
Performs addition.
Adds the value of the FixedPoint parameter to the value of the FixedPoint object whose method was called and returns the FixedPoint object whose method was called.
n
- The FixedPoint object holding the fixed-point value to be addedpublic FixedPoint add(int n)
Performs addition.
Adds the fixed-point value of the parameter to the value of the FixedPoint object whose method was called and returns the FixedPoint object whose method was called.
n
- The fixed-point value to be added (an integer obtained by multiplying a decimal value by 65536)public FixedPoint subtract(FixedPoint n)
Performs subtraction.
Subtracts from the value of the FixedPoint object whose method was called the value of the FixedPoint parameter and returns the FixedPoint object whose method was called.
n
- The FixedPoint object holding the fixed-point value to be subtractedpublic FixedPoint subtract(int n)
Performs subtraction.
Subtracts from the value of the FixedPoint object whose method was called the fixed-point value of the parameter and returns the FixedPoint object whose method was called.
n
- The fixed-point value to be subtracted (an integer obtained by multiplying a decimal value by 65536)public FixedPoint multiply(FixedPoint n)
Performs multiplication.
Multiplies the value of the FixedPoint object whose method was called by the value of the FixedPoint parameter and returns the object whose method was called.
n
- The FixedPoint object holding the multiplier.public FixedPoint multiply(int n)
Performs multiplication.
Multiplies the value of the FixedPoint object whose method was called by the fixed-point value of the parameter and returns the object whose method was called.
n
- The fixed-point multiplier value (an integer obtained by multiplying a decimal value by 65536)public FixedPoint divide(FixedPoint n)
Performs division.
Divides the value of the FixedPoint object whose method was called by the value of the FixedPoint parameter and returns the object whose method was called.
n
- The FixedPoint object holding the divisor.ArithmeticException
- if the divisor is 0.public FixedPoint divide(int n)
Performs division.
Divides the value of the FixedPoint object whose method was called by the fixed-point value of the parameter and returns the object whose method was called.
n
- The fixed-point divisor value (an integer obtained by multiplying a decimal value by 65536)ArithmeticException
- if the divisor is 0.public FixedPoint sin(FixedPoint r)
Calculates sin.
Finds the sine of the fixed-point value (in radians) of the FixedPoint object designated in the parameter and returns the result by setting it in the fixed-point value of the FixedPoint object whose method was called.
r
- The FixedPoint object holding the angle (in radians)public FixedPoint cos(FixedPoint r)
Calculates cos.
Finds the cosine of the fixed-point value (in radians) of the FixedPoint object designated in the parameter, and returns the result by setting it in the fixed-point value of the FixedPoint object whose method was called.
r
- The FixedPoint object holding the angle (in radians)public FixedPoint tan(FixedPoint r)
Calculates tan.
Finds the tangent of the fixed-point value (in radians) of the FixedPoint object designated in the parameter, and returns the result by setting it in the fixed-point value of the FixedPoint object whose method was called.
r
- The FixedPoint object holding the angle (in radians)public FixedPoint asin(FixedPoint v)
Calculates arcsin. The range is - pi/2 <= theta <= pi/2.
Finds the inverse sine (in radians) of the fixed-point value of the FixedPoint object designated in the v parameter, and returns the result by setting it in the fixed-point value of the FixedPoint object whose method was called.
v
- The FixedPoint object holding the sine value.ArithmeticException
- if the sine value designated in v is not within
the range between -1 and +1.public FixedPoint acos(FixedPoint v)
Calculates arccos. The range is 0 <= theta <= pi.
Finds the inverse cosine (in radians) of the fixed-point value of the FixedPoint object designated in the v parameter, and returns the result by setting it in the fixed-point value of the FixedPoint object whose method was called.
v
- The FixedPoint object holding the cosine value.ArithmeticException
- if the cosine value designated in v is not within
the range between -1 and +1.public FixedPoint atan(FixedPoint v)
Calculates arctan. The range is - pi/2 < value < pi/2.
Finds the inverse tangent (in radians) of the fixed-point value of the FixedPoint object designated in the v parameter, and returns the result by setting it in the fixed-point value of the FixedPoint object whose method was called.
v
- The FixedPoint object holding the tangent value.public FixedPoint sqrt()
Calculates a square root.
Finds the square root of the fixed-point value of the FixedPoint object and returns the result by setting it in the object.
ArithmeticException
- if the fixed-point value of the FixedPoint object is
negative.public FixedPoint inverse()
Calculates an inverse.
Finds the inverse of the fixed-point value of the FixedPoint object and returns the result by setting it in the object.
ArithmeticException
- if the fixed-point value of the FixedPoint object is 0.public FixedPoint pow()
Calculates a square.
Finds the square of the fixed-point value of the FixedPoint object and returns the result by setting it in the object.
public boolean isInfinite()
public FixedPoint clone()
Copies an object.
Creates and returns an object of the same contents.
public static FixedPoint getPI()
Gets pi (a circular constant).
Creates and returns a FixedPoint object holding pi.
public static FixedPoint getMaximum()
Gets a maximum value.
Creates and returns a FixedPoint object holding the maximum value.
public static FixedPoint getMinimum()
Gets a minimum value.
Creates and returns a FixedPoint object holding the minimum value.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |