|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--net.jscience.math.waba.MathFP
This class implements 32 bit fixed-point integer math functions.
The intend is to support floating point like calculations on the WABA platform.
For more details on MathFP see the documentation of net.jscience.math.kvm.MathFP
Example:
int n = MathFP.toFP(12);
int m = MathFP.toFP("14.5");
int a = n + m;
a = a - MathFP.toFP("1.5");
a = MathFP.div(a,n);
a = MathFP.sqrt(a);
System.out.println(MathFP.toString(a));
Author: Onno Hommes
Version: 2.0.6
| Field Summary | |
static int |
E
The fixed-point representation of the natural number (2.7183). |
static int |
MAX_VALUE
The maximum fixed-point representation for the current precision. |
static int |
MIN_VALUE
The minimum fixed-point representation for the current precision. |
static int |
PI
The fixed-point representation of pi (3.1416) |
| Constructor Summary | |
MathFP()
|
|
| Method Summary | |
static int |
abs(int n)
Returns the absolute value of the fixed-point integer. |
static int |
acos(int r)
Returns the arc cosine of the fixed-point integer. |
static int |
add(int n,
int m)
Adds two fixed-point integers. |
static int |
asin(int x)
Returns the arc sine of the fixed-point integer. |
static int |
atan(int r)
Returns the arc tangent of the radian fixed-point integer. |
static int |
atan2(int y,
int x)
Returns the pricipal value of the arc tangent of y/x |
static int |
convert(int l,
int o)
Changes precision of a fixed-point integer. |
static int |
cos(int r)
Returns the cosine of the radian fixed-point integer. |
static int |
cot(int r)
Returns the cotangent of the radian fixed-point integer. |
static int |
div(int n,
int m)
Divides two fixed-point integers. |
static int |
exp(int x)
The natural number raised to the power of a fixed-point integer. |
static int |
getPrecision()
Get the current runtime precision for MathFP. |
static int |
log(int s)
Returns the natural logarithm of a fixed-point integer. |
static int |
max(int n,
int m)
Returns the biggest number of the two fixed-point integers. |
static int |
min(int n,
int m)
Returns the smallest number of the two fixed-point integers. |
static int |
mul(int n,
int m)
Multiplies two fixed-point integers. |
static int |
pow(int b,
int e)
Returns a fixed-point integer raised to a fixed-point integer |
static int |
round(int x,
int d)
rounds a fixed-point integer. |
static int |
setPrecision(int p)
Set the runtime precision for MathFP. |
static int |
sin(int r)
Returns the sine of the radian fixed-point integer. |
static int |
sqrt(int n)
Returns the square root of the the fixed-point integer. |
static int |
sqrt(int n,
int r)
Returns the square root of the the fixed-point integer. |
static int |
stat()
Returns the internal overflow value if any |
static int |
sub(int n,
int m)
Subtracts two fixed-point integers. |
static int |
tan(int r)
Returns the tangent of the radian fixed-point integer. |
static int |
toFP(int l)
Converts a normal int to a fixed-point integer. |
static int |
toFP(java.lang.String s)
Converts a string input to a fixed-point integer. |
static int |
toInt(int x)
Converts a fixed-point integer to a int. |
static java.lang.String |
toString(int l)
Converts a fixed-point integer to a string. |
static java.lang.String |
toString(int x,
int d)
Converts a fixed-point integer to a string with rounding. |
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static int PI
public static int E
public static final int MAX_VALUE
public static final int MIN_VALUE
| Constructor Detail |
public MathFP()
| Method Detail |
public static int setPrecision(int p)
The precision can be anywhere from 12 to 0 bits. However using 0 bits for the precision makes no sense for this library. The lowest setting would usually be 3. The default precision is 12 bits for the fraction.
p - the number of fractional bits.public static int getPrecision()
The current precision is expressed in the number of bits used for the fractional part.
public static int toInt(int x)
This method will round the fixed point integer before converting it to a normal int. To avoid rounding you can shift the value precision bits to the right.
x - the fixed-point integer to be converted.public static int toFP(int l)
The input int will be shifted the number of fraction bits to the left.
l - the int to be converted to a fixed-point integer
public static int convert(int l,
int o)
See net.jscience.math.MathFP for more details.
l - the fixed-point to change the precision of.o - the current precision of the fixed-point integer.public static int toFP(java.lang.String s)
See net.jscience.math.MathFP for more details.
s - the String to be converted to a fixed-point integer.java.lang.NumberFormatException - if the input is invalid.public static java.lang.String toString(int l)
See net.jscience.math.MathFP for more details.
x - the fixed-point integer to be converted.
public static java.lang.String toString(int x,
int d)
Possible values for d are 0 through 8 depending on the current runtime precision. See net.jscience.math.MathFP for more details.
x - the fixed-point integer to be converted.d - the number of digits to show of the fraction.
public static int max(int n,
int m)
See net.jscience.math.MathFP for more details.
n - a fixed-point integer.m - a fixed-point integer.
public static int min(int n,
int m)
See net.jscience.math.MathFP for more details.
n - a fixed-point integer.m - a fixed-point integer.
public static int round(int x,
int d)
The maximum number of digits to round to is 4 but can be lower depending on the current runtime precision. See net.jscience.math.MathFP for more details.
x - the fixed-point integer to be roundedd - the number of precision digits to round to.
public static int mul(int n,
int m)
See net.jscience.math.MathFP for more details.
n - the fixed-point integer to be multiplied.m - the fixed-point integer multiplierNothing - but sets err_no flag
public static int div(int n,
int m)
See net.jscience.math.MathFP for more details.
n - the dividend fixed-point integer.m - the divider fixed-point integer.
public static int add(int n,
int m)
See net.jscience.math.MathFP for more details.
n - the fixed-point integer to add to.m - the fixed-point integer to be added.
public static int sub(int n,
int m)
See net.jscience.math.MathFP for more details.
n - the fixed-point integer to subtract from.m - the fixed-point integer to be subtracted.public static int abs(int n)
See net.jscience.math.MathFP for more details.
n - the fixed-point integer to get the absolute value of.
public static int sqrt(int n,
int r)
See net.jscience.math.MathFP for more details. However the value for r would normally not have to be bigger then 16.
This method uses the Newton method to extract the root.
n - the fixed-point integer to extract the root from.r - an integer that specifies the number of iterations.Nothing - but sets err_no flagpublic static int sqrt(int n)
See net.jscience.math.MathFP for more details.
n - the fixed-point integer to extract the root from.Nothing - but sets err_no flagpublic static int sin(int r)
See net.jscience.math.MathFP for more details.
r - the radian fixed-point integer to get the sine value of.public static int asin(int x)
See net.jscience.math.MathFP for more details.
s - a fixed-point integer to get the arc sine of.ArithmeticException - if the input is < -1 and > 1.public static int cos(int r)
See net.jscience.math.MathFP for more details.
r - the radian fixed-point integer to get the cosine value of.public static int acos(int r)
See net.jscience.math.MathFP for more details.
s - a fixed-point integer to get the arc sine of.ArithmeticException - if the input is < -1 and > 1.public static int tan(int r)
See net.jscience.math.MathFP for more details.
r - the radian fixed-point integer to get the tangent value of.ArithmeticException - if the input is PI/2 or any multplication of it.public static int cot(int r)
See net.jscience.math.MathFP for more details.
r - the radian fixed-point integer to get the tangent value of.ArithmeticException - if the input is 0, PI or any multplication of it.public static int atan(int r)
See net.jscience.math.MathFP for more details.
r - the radian fixed-point integer to get the tangent value of.ArithmeticException. - public static int exp(int x)
See net.jscience.math.MathFP for more details.
x - the fixed-point integer exponent.ArithmeticException - if the function overflowspublic static int log(int s)
See net.jscience.math.MathFP for more details.
s - the fixed-point integer to get the logarithm of.ArithmeticException - if the input is <= 0.
public static int pow(int b,
int e)
See net.jscience.math.MathFP for more details.
b - the fixed-point integer base.e - the fixed-point integer exponent.ArithmeticException - if the function overflows.public static int stat()
An err_no equal to 0 means no bad input or overflow. A value of 1 means bad input argument A value of 2 means overflow detected
public static int atan2(int y,
int x)
Compute the principal value of the arc tangent of y/x, using the signs of both parameters to determine the quadrant of the return value or inother words computes elementwise the angle in radian between the positive part of the x-axis and the line with origin in (0,0) which contains the point (x, y).
y - the fixed-point integerx - the fixed-point integer
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||