|
J avolution v5.2 (J2SE 1.5+) | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavolution.lang.MathLib
public final class MathLib
This utility class ensures cross-platform portability of the math
library. Functions not supported by the platform are emulated.
Developers may replace the current implementation with native
implementations for faster execution (unlike
java.lang.Math
this class can be customized).
Field Summary | |
---|---|
static double |
E
The natural logarithm. |
static double |
FOUR_PI
Four time the ratio of the circumference of a circle to its diameter. |
static double |
HALF_PI
Half the ratio of the circumference of a circle to its diameter. |
static double |
Infinity
Infinity. |
static double |
LOG10
The natural logarithm of ten. |
static double |
LOG2
The natural logarithm of two. |
static double |
NaN
Not-A-Number. |
static double |
PI
The ratio of the circumference of a circle to its diameter. |
static double |
PI_SQUARE
Holds PI * PI . |
static double |
SQRT2
The square root of two. |
static double |
TWO_PI
Twice the ratio of the circumference of a circle to its diameter. |
Method Summary | |
---|---|
static double |
abs(double d)
Returns the absolute value of the specified double argument. |
static float |
abs(float f)
Returns the absolute value of the specified float argument. |
static int |
abs(int i)
Returns the absolute value of the specified int argument. |
static long |
abs(long l)
Returns the absolute value of the specified long argument. |
static double |
acos(double x)
Returns the arc cosine of the specified value, in the range of 0.0 through pi. |
static double |
asin(double x)
Returns the arc sine of the specified value, in the range of -pi/2 through pi/2. |
static double |
atan(double x)
Returns the arc tangent of the specified value, in the range of -pi/2 through pi/2. |
static double |
atan2(double y,
double x)
Returns the angle theta such that (x == cos(theta)) && (y == sin(theta)) . |
static int |
bitLength(int i)
Returns the number of bits in the minimal two's-complement representation of the specified int , excluding a sign bit. |
static int |
bitLength(long l)
Returns the number of bits in the minimal two's-complement representation of the specified long , excluding a sign bit. |
static double |
ceil(double x)
Returns the smallest (closest to negative infinity) double value that is not less than the argument and is
equal to a mathematical integer. |
static double |
cos(double radians)
Returns the trigonometric cosine of the specified angle in radians. |
static double |
cosh(double x)
Returns the hyperbolic cosine of x. |
static int |
digitLength(int i)
Returns the number of digits in the minimal ten's-complement representation of the specified int , excluding a sign bit. |
static int |
digitLength(long l)
Returns the number of digits in the minimal ten's-complement representation of the specified long , excluding a sign bit. |
static double |
exp(double x)
Returns e raised to the specified power. |
static double |
floor(double x)
Returns the largest (closest to positive infinity) double value that is not greater than the argument and
is equal to a mathematical integer. |
static int |
floorLog10(double d)
Returns the largest power of 10 that is less than or equal to the the specified positive value. |
static int |
floorLog2(double d)
Returns the largest power of 2 that is less than or equal to the the specified positive value. |
static double |
log(double x)
Returns the natural logarithm (base e ) of the specified
value. |
static double |
log10(double x)
Returns the decimal logarithm of the specified value. |
static double |
max(double x,
double y)
Returns the greater of two double values. |
static float |
max(float x,
float y)
Returns the greater of two float values. |
static int |
max(int x,
int y)
Returns the greater of two int values. |
static long |
max(long x,
long y)
Returns the greater of two long values. |
static double |
min(double x,
double y)
Returns the smaller of two double values. |
static float |
min(float x,
float y)
Returns the smaller of two float values. |
static int |
min(int x,
int y)
Returns the smaller of two int values. |
static long |
min(long x,
long y)
Returns the smaller of two long values. |
static double |
pow(double x,
double y)
Returns the value of the first argument raised to the power of the second argument. |
static double |
random()
Returns a random number between zero and one. |
static double |
random(double min,
double max)
Returns a pseudo random double value in the range
[min, max] (fast and thread-safe without synchronization). |
static float |
random(float min,
float max)
Returns a pseudo random float value in the range
[min, max] (fast and thread-safe without synchronization). |
static int |
random(int min,
int max)
Returns a pseudo random int value in the range
[min, max] (fast and thread-safe without synchronization). |
static long |
random(long min,
long max)
Returns a pseudo random long value in the range
[min, max] (fast and thread-safe without synchronization). |
static double |
rem(double x,
double y)
Returns the remainder of the division of the specified two arguments. |
static long |
round(double d)
Returns the closest long to the specified argument. |
static int |
round(float f)
Returns the closest int to the specified argument. |
static double |
sin(double radians)
Returns the trigonometric sine of the specified angle in radians. |
static double |
sinh(double x)
Returns the hyperbolic sine of x. |
static double |
sqrt(double x)
Returns the positive square root of the specified value. |
static double |
tan(double radians)
Returns the trigonometric tangent of the specified angle in radians. |
static double |
tanh(double x)
Returns the hyperbolic tangent of x. |
static double |
toDegrees(double radians)
Converts an angle in radians to degrees. |
static double |
toDoublePow10(long m,
int n)
Returns the closest double representation of the
specified long number multiplied by a power of ten. |
static double |
toDoublePow2(long m,
int n)
Returns the closest double representation of the
specified long number multiplied by a power of two. |
static long |
toLongPow10(double d,
int n)
Returns the closest long representation of the
specified double number multiplied by a power of ten. |
static long |
toLongPow2(double d,
int n)
Returns the closest long representation of the
specified double number multiplied by a power of two. |
static double |
toRadians(double degrees)
Converts an angle in degrees to radians. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final double E
public static final double PI
public static final double HALF_PI
public static final double TWO_PI
public static final double FOUR_PI
public static final double PI_SQUARE
PI
* PI
.
public static final double LOG2
public static final double LOG10
public static final double SQRT2
public static final double NaN
public static final double Infinity
Method Detail |
---|
public static int random(int min, int max)
int
value in the range
[min, max]
(fast and thread-safe without synchronization).
min
- the minimum value inclusive.max
- the maximum value exclusive.
[min, max]
.public static long random(long min, long max)
long
value in the range
[min, max]
(fast and thread-safe without synchronization).
min
- the minimum value inclusive.max
- the maximum value inclusive.
[min, max]
.public static float random(float min, float max)
float
value in the range
[min, max]
(fast and thread-safe without synchronization).
min
- the minimum value inclusive.max
- the maximum value inclusive.
[min, max]
.public static double random(double min, double max)
double
value in the range
[min, max]
(fast and thread-safe without synchronization).
min
- the minimum value inclusive.max
- the maximum value inclusive.
[min, max]
.public static int bitLength(int i)
int
, excluding a sign bit.
For positive int
, this is equivalent to the number of bits
in the ordinary binary representation. For negative int
,
it is equivalent to the number of bits of the positive value
-(i + 1)
.
i
- the int
value for which the bit length is returned.
i
.public static int bitLength(long l)
long
, excluding a sign bit.
For positive long
, this is equivalent to the number of bits
in the ordinary binary representation. For negative long
,
it is equivalent to the number of bits of the positive value
-(l + 1)
.
l
- the long
value for which the bit length is returned.
l
.public static int digitLength(int i)
int
, excluding a sign bit.
For positive int
, this is equivalent to the number of digit
in the ordinary decimal representation. For negative int
,
it is equivalent to the number of digit of the positive value
-(i + 1)
.
i
- the int
value for which the digit length is returned.
i
.public static int digitLength(long l)
long
, excluding a sign bit.
For positive long
, this is equivalent to the number of digit
in the ordinary decimal representation. For negative long
,
it is equivalent to the number of digit of the positive value
-(value + 1)
.
l
- the long
value for which the digit length is returned.
l
.public static double toDoublePow2(long m, int n)
double
representation of the
specified long
number multiplied by a power of two.
m
- the long
multiplier.n
- the power of two exponent.
m * 2n
.public static double toDoublePow10(long m, int n)
double
representation of the
specified long
number multiplied by a power of ten.
m
- the long
multiplier.n
- the power of ten exponent.
multiplier * 10n
.public static long toLongPow2(double d, int n)
long
representation of the
specified double
number multiplied by a power of two.
d
- the double
multiplier.n
- the power of two exponent.
d * 2n
java.lang.ArithmeticException
- if the conversion cannot be performed
(NaN, Infinity or overflow).public static long toLongPow10(double d, int n)
long
representation of the
specified double
number multiplied by a power of ten.
d
- the double
multiplier.n
- the power of two exponent.
d * 10n
.public static int floorLog2(double d)
d
- the double
number.
floor(Log2(abs(d)))
java.lang.ArithmeticException
- if d <= 0 or d
is NaN
or Infinity
.
public static int floorLog10(double d)
d
- the double
number.
floor(Log10(abs(d)))
java.lang.ArithmeticException
- if d <= 0 or d
is NaN
or Infinity
.
public static double toRadians(double degrees)
degrees
- the angle in degrees.
public static double toDegrees(double radians)
radians
- the angle in radians.
public static double sqrt(double x)
x
- the value.
java.lang.Math.sqrt(x)
public static double rem(double x, double y)
x
- the dividend.y
- the divisor.
x - round(x / y) * y
public static double ceil(double x)
double
value that is not less than the argument and is
equal to a mathematical integer.
x
- the value.
java.lang.Math.ceil(x)
public static double floor(double x)
double
value that is not greater than the argument and
is equal to a mathematical integer.
x
- the value.
java.lang.Math.ceil(x)
public static double sin(double radians)
radians
- the angle in radians.
java.lang.Math.sin(radians)
public static double cos(double radians)
radians
- the angle in radians.
java.lang.Math.cos(radians)
public static double tan(double radians)
radians
- the angle in radians.
java.lang.Math.tan(radians)
public static double asin(double x)
x
- the value whose arc sine is to be returned.
public static double acos(double x)
x
- the value whose arc cosine is to be returned.
public static double atan(double x)
x
- the value whose arc tangent is to be returned.
public static double atan2(double y, double x)
(x == cos(theta)) && (y == sin(theta))
.
y
- the y value.x
- the x value.
public static double sinh(double x)
x
- the value for which the hyperbolic sine is calculated.
(exp(x) - exp(-x)) / 2
public static double cosh(double x)
x
- the value for which the hyperbolic cosine is calculated.
(exp(x) + exp(-x)) / 2
public static double tanh(double x)
x
- the value for which the hyperbolic tangent is calculated.
(exp(2 * x) - 1) / (exp(2 * x) + 1)
public static double exp(double x)
e
raised to the specified power.
x
- the exponent.
ex
public static double log(double x)
e
) of the specified
value.
x
- the value greater than 0.0
.
ey == x
public static double log10(double x)
x
- the value greater than 0.0
.
10y == x
public static double pow(double x, double y)
x
- the base.y
- the exponent.
xy
public static int round(float f)
int
to the specified argument.
f
- the float
value to be rounded to a int
int
value.public static long round(double d)
long
to the specified argument.
d
- the double
value to be rounded to a
long
long
value.public static double random()
double
greater than or equal
to 0.0
and less than 1.0
.public static int abs(int i)
int
argument.
i
- the int
value.
i
or -i
public static long abs(long l)
long
argument.
l
- the long
value.
l
or -l
public static float abs(float f)
float
argument.
f
- the float
value.
f
or -f
public static double abs(double d)
double
argument.
d
- the double
value.
d
or -d
public static int max(int x, int y)
int
values.
x
- the first value.y
- the second value.
x
and y
.public static long max(long x, long y)
long
values.
x
- the first value.y
- the second value.
x
and y
.public static float max(float x, float y)
float
values.
x
- the first value.y
- the second value.
x
and y
.public static double max(double x, double y)
double
values.
x
- the first value.y
- the second value.
x
and y
.public static int min(int x, int y)
int
values.
x
- the first value.y
- the second value.
x
and y
.public static long min(long x, long y)
long
values.
x
- the first value.y
- the second value.
x
and y
.public static float min(float x, float y)
float
values.
x
- the first value.y
- the second value.
x
and y
.public static double min(double x, double y)
double
values.
x
- the first value.y
- the second value.
x
and y
.
|
J avolution v5.2 (J2SE 1.5+) | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |