fpmath
fpmath.FPMath Class Reference

List of all members.

## Static Public Member Functions

static int abs (int fp)
static int add (int fpA, int fpB)
static int atan (int fp)
static int atan2 (int fpY, int fpX)
static int ceil (int fp)
static int cos (int fp)
static int div (int fpA, int fpB)
static int exp (int fp)
static int floor (int fp)
static int fraction (int fp)
static int log (int fp)
static int max (int fpA, int fpB)
static int min (int fpA, int fpB)
static int mul (int fpA, int fpB)
static int pow (int fpBase, int fpPower)
static int round (int fp)
static int roundToInt (int fp)
static int sin (int fp)
static int sqrt (int fp)
static int sub (int fpA, int fpB)
static int toFP (int integer)
static int toInt (int fp)
static int toFP (String s) throws NumberFormatException
static String toString (int fp)

## Static Public Attributes

static final int EPSILON = 1
static final int MAX_VALUE = 0x7FFFFFFF
static final int MIN_VALUE = 0x80000000

## Detailed Description

16.16 Fixed Point Math libray using 16-bit, 32-bit and 64-bit integer arithmetic and look-up tables.

• This documentation denotes fixed point numbers as `FP int`s to distinguish them from integer numbers. However `FP int` are in fact plain `int` primitives.
• Its good programming practice to start all `FP int` variable and attribute names with 'f' or 'fp' to distinguish them from integer `int`s.
• Usage of Java built-in integer aritmetic operators (+, -, *, /, %, &, |, ^, <<, >>, >>>) for fixed point calculations should be kept to a minimum. Use the methods offered here instead.
• Built-in Java comparison operators (<, <=, ==, !=, >=, >) may be used to compare `FP int`s to other `FP int`s, but not to compare `FP int`s to other integer `int`s.
• All methods presented in this class are defined as `static` for performance reasons.
• The worst-case error of each method is mentioned in its description and is measured in `EPSILON`s, the smallest positive non-zero number a `FP int` can have.
• The internal look-up tables are stored hard-coded and have been thoroughly optimized for size, resulting in a total of 560 bytes.
• Non-linear monotic functions are NOT guaranteed to produce monotonic `FP int`results, but will never differ more than the wost-case error of these methods.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

• Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

• Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

## Member Function Documentation

 static int fpmath.FPMath.abs ( int fp ) ` [static]`

Returns the absolute value of the specified `FP int` as a `FP int`.

Maximum deviation from definition: 0 `EPSILON`.

Parameters:
 fp The `FP int` value.
Returns:
A `FP int` containing the absolute value.
 static int fpmath.FPMath.add ( int fpA, int fpB ) ` [static]`

Returns the result of the addition of the two specified `FP int` parameters as a `FP int`.

Maximum deviation from definition: 0 `EPSILON`.

Parameters:
 fpA First `FP int` parameter. fpB Second `FP int` parameter.
Returns:
A `FP int` containing the result of this calculation.
 static int fpmath.FPMath.atan ( int fp ) ` [static]`

Returns the inverse tangent of the specified `FP int` parameter as a `FP int`.

The result is specified in 1/65536ths of a full rotation and is returned in the range of 0.0 through 0.25 and 0.75 through 1.0-`EPSILON`.

Maximum deviation from definition: 2 `EPSILON`.

Parameters:
 fp The `FP int` containing the tangent.
Returns:
A `FP int` containing the result of this calculation.
 static int fpmath.FPMath.atan2 ( int fpY, int fpX ) ` [static]`

Returns the polar angle from the cartesian input vector, specified as an y-component `FP int` and x-component `FP int`, as a `FP int`.

The result is specified in 1/65536ths of a full rotation and is returned in the range of 0.0 through (1.0-`EPSILON`).

Maximum deviation from definition: 2 `EPSILON`.

Parameters:
 fpY The `FP int` containing the Y-component. fpX The `FP int` containing the X-component.
Returns:
A `FP int` containing the result of this calculation.
 static int fpmath.FPMath.ceil ( int fp ) ` [static]`

Returns the smallest integer that is equal or greater than specified `FP int` as a `FP int`.

Maximum deviation from definition: 0 `EPSILON`.

Parameters:
 fp The `FP int` value.
Returns:
A `FP int` containing the result of this calculation.
 static int fpmath.FPMath.cos ( int fp ) ` [static]`

Returns the cosine of the specified angle `FP int` parameter as a `FP int`.

Maximum deviation from definition: 2 `EPSILON`.

Parameters:
 fp The `FP int` containing the angle. This should be specified in 1/65536ths of a full rotation.
Returns:
A `FP int` containing the result of this calculation.
 static int fpmath.FPMath.div ( int fpA, int fpB ) ` [static]`

Returns the result of the division of the first specified `FP int` parameter by the second specified `FP int` parameter as a (rounded down) `FP int`.

Maximum deviation from definition: 0 `EPSILON`.

Parameters:
 fpA First `FP int` parameter. fpB Second `FP int` parameter.
Returns:
A `FP int` containing the result of this calculation.
 static int fpmath.FPMath.exp ( int fp ) ` [static]`

Returns the Euler's number e raised to the power of the specified `FP int` parameter as a `FP int`. Results greater than MAX_VALUE are clamped to MAX_VALUE.

Maximum deviation from definition:

• power `FP int` < -1 : 1 `EPSILON`
• -1 <= power `FP int` < 0 : 2 `EPSILON`
• power `FP int` >= 0 : Returned `FP int` * 2-14 `EPSILON`
Parameters:
 fp The `FP int` containing the power.
Returns:
A `FP int` containing the result of this calculation.
 static int fpmath.FPMath.floor ( int fp ) ` [static]`

Returns the largest integer that is equal or smaller than specified `FP int` as a `FP int`.

Maximum deviation from definition: 0 `EPSILON`.

Parameters:
 fp The `FP int` value.
Returns:
A `FP int` containing the result of this calculation.
 static int fpmath.FPMath.fraction ( int fp ) ` [static]`

Returns the fraction of the specified `FP int` in 1/65536ths as in `int` integer.

Maximum deviation from definition: 0 `EPSILON`.

Parameters:
 fp `FP int` parameter.
Returns:
A `int` containing the fraction in 1/65536ths.
 static int fpmath.FPMath.log ( int fp ) ` [static]`

Returns the natural logaritm (base Euler's number e) of the specified `FP int` parameter as a `FP int`. All non-positive parameters return `MIN_VALUE`.

Maximum deviation from definition: 4 `EPSILON`.

Parameters:
 fp The `FP int` containing the input number.
Returns:
A `FP int` containing the result of this calculation.
 static int fpmath.FPMath.max ( int fpA, int fpB ) ` [static]`

Returns the larger of the two specified `FP int`s.

Maximum deviation from definition: 0 `EPSILON`.

Parameters:
 fpA The first `FP int` value. fpB The second `FP int` value.
Returns:
A `FP int` containing the largest value of the two.
 static int fpmath.FPMath.min ( int fpA, int fpB ) ` [static]`

Return the smaller of the two specified `FP int`s.

Maximum deviation from definition: 0 `EPSILON`.

Parameters:
 fpA The first `FP int` value. fpB The second `FP int` value.
Returns:
A `FP int` containing the smallest value of the two.
 static int fpmath.FPMath.mul ( int fpA, int fpB ) ` [static]`

Returns the result of the multiplication the two specified `FP int` parameters as a (rounded down) `FP int`.

Maximum deviation from definition: 0 `EPSILON`.

Parameters:
 fpA First `FP int` parameter. fpB Second `FP int` parameter.
Returns:
A `FP int` containing the result of this calculation.
 static int fpmath.FPMath.pow ( int fpBase, int fpPower ) ` [static]`

Returns the base specified by the first `FP int` parameter raised to the power specified by the second `FP int` parameter as a `FP int`. However, all negative bases return 0.

Maximum deviation from definition: Depends on both parameters.

Parameters:
 fpBase The `FP int` containing the base. fpPower The `FP int` containing the power.
Returns:
A `FP int` containing the result of this calculation.
 static int fpmath.FPMath.round ( int fp ) ` [static]`

Returns the integer closest to the specified `FP int` as a `FP int`.

Maximum deviation from definition: 0

Parameters:
 fp The `FP int` value.
Returns:
A `FP int` containing the result of this calculation.
 static int fpmath.FPMath.roundToInt ( int fp ) ` [static]`

Returns the integer closest to the specified `FP int` as a `int` integer.

Maximum deviation from definition: 0

Parameters:
 fp The `FP int` value.
Returns:
A `int` integer containing the result of this calculation.
 static int fpmath.FPMath.sin ( int fp ) ` [static]`

Returns the sine of the specified angle `FP` parameter as a `FP int`.

Maximum deviation from definition: 2 `EPSILON`.

Parameters:
 fp The `FP int` containing the angle. This should be specified in 1/65536ths of a full rotation.
Returns:
This `FP int` containing the result of this calculation.
 static int fpmath.FPMath.sqrt ( int fp ) ` [static]`

Returns the square root of the specified `FP` parameter as a `FP int`. Negative parameters return 0.

Maximum deviation from definition: 1 `EPSILON`.

Parameters:
 fp The `FP int` containing the input number.
Returns:
This `FP int` containing the result of this calculation.
 static int fpmath.FPMath.sub ( int fpA, int fpB ) ` [static]`

Returns the result of the substraction of the second specified `FP int` parameter from the first specified `FP` parameter as a `FP int`.

Maximum deviation from definition: 0 `EPSILON`.

Parameters:
 fpA First `FP int` parameter. fpB Second `FP int` parameter.
Returns:
A `FP int` containing the result of this calculation.
 static int fpmath.FPMath.toFP ( int integer ) ` [static]`

Returns the `FP int` representation of the integer specified by the `int` integer.

Maximum deviation from definition: 0 `EPSILON`.

Parameters:
 integer The integer value.
Returns:
A `FP int` containing the specified integer value.
 static int fpmath.FPMath.toFP ( String s ) throws NumberFormatException ` [static]`

Returns the `FP int` value representing the floating point number indicated by the `String` parameter. Does not support floating point E notations.

Maximum deviation from definition: 0.5 `EPSILON`.

Parameters:
 s `String` containing a floating point number.
Returns:
This `FP int` containing the closest 16.16 fixed point to the specified floating point number.
 static int fpmath.FPMath.toInt ( int fp ) ` [static]`

Returns the largest integer number smaller than the specified `FP int` as a `int`.

Maximum deviation from definition: 0 `EPSILON`.

Parameters:
 fp The `FP int` value.
Returns:
An `int` containing the integer value.
 static String fpmath.FPMath.toString ( int fp ) ` [static]`

Returns a `String` containing a floating point number representation of the specified `FP int` number.

Parameters:
 fp The `FP int` containing the input number.
Returns:
A `String` representation of this `FP int`.

## Member Data Documentation

 final int fpmath.FPMath.EPSILON = 1` [static]`

A `FP int` constant holding the smallest positive non-zero value a `FP int` can have, 2-16.

 final int fpmath.FPMath.MAX_VALUE = 0x7FFFFFFF` [static]`

A `FP int` constant holding the maximum value a `FP int` can have, 215 - 2-16.

 final int fpmath.FPMath.MIN_VALUE = 0x80000000` [static]`

A `FP int` constant holding the miminum value a `FP int` can have, -215.

The documentation for this class was generated from the following file: