public abstract class MathUtil
- Object
- MathUtil
MathUtil for Java ME.
This fills the gap in Java ME Math with a port of Sun’s public FDLIBM C-library for IEEE-754.
Constructors
public MathUtil() |
Methods
public static final double exp(double a) | Return Math.E to the exponent a. This in turn uses ieee7854_exp(double). |
public static final double log(double a) | Return the natural logarithm, ln(a), as it relates to Math.E. |
public static final double log10(double a) | Return the common base-10 logarithm, log10(a). |
public static final double pow(double a, double b) | Return a to the power of b, sometimes written as a ** b but not to be confused with the bitwise ^ operator. This in turn uses ieee7854_log(double). |
public static final double asin(double a) | Return the arcsine of a. |
public static final double acos(double a) | Return the arccosine of a. |
public static final double atan(double a) | Return the arctangent of a, call it b, where a = tan(b). |
public static final double atan2(double b, double a) | For any real arguments x and y not both equal to zero, atan2(y, x) is the angle in radians between the positive x-axis of a plane and the point given by the coordinates (x, y) on it. |
public static double scalb(double x, int n) | scalbn (double x, int n) scalbn(x,n) returns x* 2**n computed by exponent manipulation rather than by actually performing an exponentiation or a multiplication. |
public static double scalbn(double x, int n) | Deprecated Please update your code to use scalb |
public static double copySign(double x, double y) | |
public static double copysign(double x, double y) | Deprecated Please update your code to use copySign |
public static double ulp(double d) | Returns the size of an ulp (units in the last place) of the argument. |
public static double nextAfter(double start, double direction) | Returns the next representable floating point number after the first argument in the direction of the second argument. |
public static int round(float a) | Rounds the number to the closest integer |
public static long round(double a) | Rounds the number to the closest integer |
public static int floor(float a) | Rounds the number down |
public static long floor(double a) | Rounds the number down |
public static int compare(float f1, float f2) | Compares the two specified float values. |
public static int compare(double d1, double d2) | Compares the two specified double values. |
Inherited methods
Constructor details
MathUtil
public MathUtil()Method details
exp
public static final double exp(double a)Return Math.E to the exponent a.
This in turn uses ieee7854_exp(double).
log
public static final double log(double a)Return the natural logarithm, ln(a), as it relates to Math.E.
This in turn uses ieee7854_log(double).
log10
public static final double log10(double a)Return the common base-10 logarithm, log10(a).
This in turn uses ieee7854_log(double)/ieee7854_log(10.0).
pow
public static final double pow(double a, double b)Return a to the power of b, sometimes written as a ** b
but not to be confused with the bitwise ^ operator.
This in turn uses ieee7854_log(double).
asin
public static final double asin(double a)Return the arcsine of a.
acos
public static final double acos(double a)Return the arccosine of a.
atan
public static final double atan(double a)Return the arctangent of a, call it b, where a = tan(b).
atan2
public static final double atan2(double b, double a)For any real arguments x and y not both equal to zero, atan2(y, x)
is the angle in radians between the positive x-axis of a plane
and the point given by the coordinates (x, y) on it.
The angle is positive for counter-clockwise angles (upper half-plane, y > 0),
and negative for clockwise angles (lower half-plane, y < 0).
This in turn uses ieee7854_arctan2(double).
scalb
public static double scalb(double x, int n)scalbn (double x, int n)
scalbn(x,n) returns x* 2**n computed by exponent
manipulation rather than by actually performing an
exponentiation or a multiplication.
scalbn
public static double scalbn(double x, int n)Deprecated. Please update your code to use scalb
Please update your code to use scalb
Returns
scalb(x, n)
copySign
public static double copySign(double x, double y)copysign
public static double copysign(double x, double y)Deprecated. Please update your code to use copySign
Please update your code to use copySign
Returns
copySign(x, y)
ulp
public static double ulp(double d)Returns the size of an ulp (units in the last place) of the argument.
Parameters
ddouble- value whose ulp is to be returned
Returns
size of an ulp for the argument
nextAfter
public static double nextAfter(double start, double direction)Returns the next representable floating point number after the first
argument in the direction of the second argument.
Parameters
startdouble- starting value
directiondouble- value indicating which of the neighboring representable floating point number to return.
Returns
The floating-point number next to
start in the direction of direction.round
public static int round(float a)Rounds the number to the closest integer
Parameters
afloat- the number
Returns
the closest integer
round
public static long round(double a)Rounds the number to the closest integer
Parameters
adouble- the number
Returns
the closest integer
floor
public static int floor(float a)Rounds the number down
Parameters
afloat- the number
Returns
a rounded down number
floor
public static long floor(double a)Rounds the number down
Parameters
adouble- the number
Returns
a rounded down number
compare
public static int compare(float f1, float f2)Compares the two specified float values. The sign
of the integer value returned is the same as that of the
integer that would be returned by the call:
float f1 = 1.5f;
float f2 = 2.5f;
int result = new Float(f1).compareTo(new Float(f2));
Form hi = new Form("MathUtil.compare(float)", BoxLayout.y());
hi.add(new Label("Float.compareTo result: " + result));
hi.show();
Parameters
f1float- the first
floatto compare. f2float- the second
floatto compare.
Returns
the value
0 if f1 is
numerically equal to f2; a value less than
0 if f1 is numerically less than
f2; and a value greater than 0
if f1 is numerically greater than
f2.compare
public static int compare(double d1, double d2)Compares the two specified double values. The sign
of the integer value returned is the same as that of the
integer that would be returned by the call:
double d1 = 1.5;
double d2 = 2.5;
int result = new Double(d1).compareTo(new Double(d2));
Form hi = new Form("MathUtil.compare(double)", BoxLayout.y());
hi.add(new Label("Double.compareTo result: " + result));
hi.show();
Parameters
d1double- the first
doubleto compare d2double- the second
doubleto compare
Returns
the value
0 if d1 is
numerically equal to d2; a value less than
0 if d1 is numerically less than
d2; and a value greater than 0
if d1 is numerically greater than
d2.