com.vodafone.v10.util
Class FixedPoint

java.lang.Object
  |
  +--com.vodafone.v10.util.FixedPoint

public class FixedPoint
extends java.lang.Object

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:


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

FixedPoint

public FixedPoint()

FixedPoint constructor.

Holds value 0.0.


FixedPoint

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.

Parameters:
value - The held fixed-point value
Method Detail

getInteger

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.

Returns:
int - The integer part

getDecimal

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).

Returns:
int - The decimal part

setValue

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.

Parameters:
value - New fixed-point value (an integer obtained by multiplying a decimal value by 65536)

add

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.

Parameters:
n - The FixedPoint object holding the fixed-point value to be added
Returns:
FixedPoint - An instance of this containing the result

add

public 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.

Parameters:
n - The fixed-point value to be added (an integer obtained by multiplying a decimal value by 65536)
Returns:
FixedPoint - An instance of this containing the result.

subtract

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.

Parameters:
n - The FixedPoint object holding the fixed-point value to be subtracted
Returns:
FixedPoint - An instance of this containing the result.

subtract

public 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.

Parameters:
n - The fixed-point value to be subtracted (an integer obtained by multiplying a decimal value by 65536)
Returns:
FixedPoint - An instance of this containing the result.

multiply

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.

Parameters:
n - The FixedPoint object holding the multiplier.
Returns:
FixedPoint - An instance of this containing the result.

multiply

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.

Parameters:
n - The fixed-point multiplier value (an integer obtained by multiplying a decimal value by 65536)
Returns:
FixedPoint - An instance of this containing the result.

divide

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.

Parameters:
n - The FixedPoint object holding the divisor.
Returns:
FixedPoint - An instance of this containing the result.
Throws:
ArithmeticException - if the divisor is 0.

divide

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.

Parameters:
n - The fixed-point divisor value (an integer obtained by multiplying a decimal value by 65536)
Returns:
FixedPoint - An instance of this containing the result.
Throws:
ArithmeticException - if the divisor is 0.

sin

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.

Parameters:
r - The FixedPoint object holding the angle (in radians)
Returns:
FixedPoint - An instance of this containing the result.

cos

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.

Parameters:
r - The FixedPoint object holding the angle (in radians)
Returns:
FixedPoint - An instance of this containing the result.

tan

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.

Parameters:
r - The FixedPoint object holding the angle (in radians)
Returns:
FixedPoint - An instance of this containing the result.

asin

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.

Parameters:
v - The FixedPoint object holding the sine value.
Returns:
FixedPoint - An instance of this containing the result.
Throws:
ArithmeticException - if the sine value designated in v is not within the range between -1 and +1.

acos

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.

Parameters:
v - The FixedPoint object holding the cosine value.
Returns:
FixedPoint - An instance of this containing the result.
Throws:
ArithmeticException - if the cosine value designated in v is not within the range between -1 and +1.

atan

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.

Parameters:
v - The FixedPoint object holding the tangent value.
Returns:
FixedPoint - An instance of this containing the result.

sqrt

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.

Returns:
FixedPoint - An instance of this containing the result.
Throws:
ArithmeticException - if the fixed-point value of the FixedPoint object is negative.

inverse

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.

Returns:
FixedPoint - An instance of this containing the result.
Throws:
ArithmeticException - if the fixed-point value of the FixedPoint object is 0.

pow

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.

Returns:
FixedPoint - An instance of this containing the result.

isInfinite

public boolean isInfinite()
Checks for overflow.
Returns:
boolean - Returns true in case of overflow.

clone

public FixedPoint clone()

Copies an object.

Creates and returns an object of the same contents.

Returns:
FixedPoint - A FixedPoint object of the same contents.

getPI

public static FixedPoint getPI()

Gets pi (a circular constant).

Creates and returns a FixedPoint object holding pi.

Returns:
FixedPoint - The FixedPoint object holding pi

getMaximum

public static FixedPoint getMaximum()

Gets a maximum value.

Creates and returns a FixedPoint object holding the maximum value.

Returns:
FixedPoint - The FixedPoint object holding the maximum value.

getMinimum

public static FixedPoint getMinimum()

Gets a minimum value.

Creates and returns a FixedPoint object holding the minimum value.

Returns:
FixedPoint - The FixedPoint object holding the minimum value.


Copyright 2002,2003 Aplix Corporation. All rights reserved. Aplix Confidential and Restricted.