fpmath
|
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 |
16.16 Fixed Point Math libray using 16-bit, 32-bit and 64-bit integer arithmetic and look-up tables.
Please note that:
FP int
s to distinguish them from integer numbers. However FP int
are in fact plain int
primitives. FP int
variable and attribute names with 'f' or 'fp' to distinguish them from integer int
s. FP int
s to other FP int
s, but not to compare FP int
s to other integer int
s. static
for performance reasons. EPSILON
s, the smallest positive non-zero number a FP int
can have. FP int
results, but will never differ more than the wost-case error of these methods.
The source code license:
Copyright (c) 2005-2011, Giliam de Carpentier. All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
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.
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
.
fp | The FP int value. |
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
.
fpA | First FP int parameter. |
fpB | Second FP int parameter. |
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
.
fp | The FP int containing the tangent. |
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
.
fpY | The FP int containing the Y-component. |
fpX | The FP int containing the X-component. |
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
.
fp | The FP int value. |
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
.
fp | The FP int containing the angle. This should be specified in 1/65536ths of a full rotation. |
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
.
fpA | First FP int parameter. |
fpB | Second FP int parameter. |
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:
FP int
< -1 : 1 EPSILON
FP int
< 0 : 2 EPSILON
FP int
>= 0 : Returned FP int
* 2-14 EPSILON
fp | The FP int containing the power. |
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
.
fp | The FP int value. |
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
.
fp | FP int parameter. |
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
.
fp | The FP int containing the input number. |
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
.
fpA | The first FP int value. |
fpB | The second FP int value. |
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
.
fpA | The first FP int value. |
fpB | The second FP int value. |
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
.
fpA | First FP int parameter. |
fpB | Second FP int parameter. |
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.
fpBase | The FP int containing the base. |
fpPower | The FP int containing the power. |
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
fp | The FP int value. |
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
fp | The FP int value. |
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
.
fp | The FP int containing the angle. This should be specified in 1/65536ths of a full rotation. |
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
.
fp | The FP int containing the input number. |
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
.
fpA | First FP int parameter. |
fpB | Second FP int parameter. |
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
.
integer | The integer value. |
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
.
s | String containing a floating point number. |
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
.
fp | The FP int value. |
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.
fp | The FP int containing the input number. |
String
representation of this FP int
. 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.