|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--extra.util.Maths
The class Math contains methods for performing basic
numeric operations such as the elementary exponential, logarithm,
square root, and trigonometric functions. One big change is that (in
general) all methods use and return floats instead of
doubles!
Math provides approximately 5 decimal place accuracy versions of the methods provided by java.math.Math. The approximations are based on those published in "Approximations for Digital Computers" by Cecil Hastings, Jr., Princeton University Press, 1955.
I chose not to use the implementations noted below from netlib (not at netlib.att.com!) as they provide more accuracy (and would be slower) than seemed needed for a hand-held device. I have left in the reference for completeness. I realized after a review of Float that one can get/set the bits for a floating value using intBitsToFloat and floatToIntBits. Therefore, it would be possible to implement the fdlibm versions of the algorithms where more accuracy and robustness is needed.
To help ensure portability of Java programs, the definitions of
many of the numeric functions in this package require that they
produce the same results as certain published algorithms. These
algorithms are available from the well-known network library
netlib as the package "Freely Distributable
Math Library" (fdlibm). These algorithms, which
are written in the C programming language, are then to be
understood as executed with all floating-point operations
following the rules of Java floating-point arithmetic.
The network library may be found on the World Wide Web at
http://netlib.att.com/
then perform a keyword search for "fdlibm".
The Java math library is defined with respect to the version of
fdlibm dated January 4, 1995. Where
fdlibm provides more than one definition for a
function (such as acos), use the "IEEE 754 core
function" version (residing in a file whose name begins with
the letter e).
| Field Summary | |
static float |
E
The double value that is closer than any other to
e, the base of the natural logarithms. |
static float |
PI
The double value that is closer than any other to
pi, the ratio of the circumference of a circle to its diameter. |
| Method Summary | |
static float |
abs(float a)
Returns the absolute value of a float value. |
static int |
abs(int a)
Returns the absolute value of a int value. |
static float |
acos(float x)
Returns the arc cosine of an angle, in the range of 0.0 through pi. |
static float |
asin(float x)
Returns the arc sine of an angle, in the range of -pi/2 through pi/2. |
static float |
atan(float a)
Returns the arc tangent of an angle, in the range of -pi/2 through pi/2. |
static float |
atan2(float y,
float x)
Converts rectangular coordinates ( b, a)
to polar (r, theta). |
static float |
cos(float radians)
Returns the trigonometric cosine of an angle. |
static float |
exp(float x)
Returns the exponential number e (i.e., 2.718...) raised to the power of a double value. |
static float |
log(float x)
Returns the natural logarithm (base e) of a float
value. |
static void |
main(String[] args)
|
static float |
max(float a,
float b)
Returns the maximum of the two given float values. |
static int |
max(int a,
int b)
Returns the maximum of the two given int values. |
static float |
min(float a,
float b)
Returns the minimum of the two given float values. |
static int |
min(int a,
int b)
Returns the minimum of the two given int values. |
static float |
pow(float a,
float b)
Returns of value of the first argument raised to the power of the second argument. |
static int |
round(float x)
Rounds the given float to the nearest whole number. |
static float |
sin(float radians)
Returns the trigonometric sine of an angle. |
static float |
sqrt(float a)
Returns the square root of a float value. |
static float |
tan(float x)
Returns the trigonometric tangent of an angle. |
| Methods inherited from class java.lang.Object |
equals, hashCode, toString |
| Field Detail |
public static final float E
double value that is closer than any other to
e, the base of the natural logarithms.public static final float PI
double value that is closer than any other to
pi, the ratio of the circumference of a circle to its diameter.| Method Detail |
public static float abs(float a)
float value.
If the argument is not negative, the argument is returned.
If the argument is negative, the negation of the argument is returned.a - a float value.public static int abs(int a)
int value.
If the argument is not negative, the argument is returned.
If the argument is negative, the negation of the argument is returned.a - a int value.public static int round(float x)
float to the nearest whole number.x - the number to round
public static int min(int a,
int b)
int values.
public static int max(int a,
int b)
int values.
public static float min(float a,
float b)
float values.
public static float max(float a,
float b)
float values.public static float asin(float x)
a - an angle, in radians.public static float acos(float x)
a - an angle, in radians.public static float tan(float x)
a - an angle, in radians.public static float atan(float a)
a - an angle, in radians.
public static float atan2(float y,
float x)
b, a)
to polar (r, theta).
This method computes the phase theta by computing an arc tangent
of b/a in the range of -pi to pi.a - a float value.b - a float value.public static float sqrt(float a)
float value.a - a float value.
a.
If the argument is NaN or less than zero, the result is NaN.public static float exp(float x)
double value.a - a double value.
public static float pow(float a,
float b)
a - a float value.b - a float value.ab.public static float log(float x)
float
value.a - a number greater than 0.0.a, the natural logarithm of
a.public static float sin(float radians)
a - an angle, in radians.public static float cos(float radians)
a - an angle, in radians.public static void main(String[] args)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||