javolution37.javolution.lang
Class MathLib
- java.lang.Object
-
- javolution37.javolution.lang.MathLib
-
public final class MathLib extends java.lang.ObjectThis 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.
-
-
Field Summary
Fields Modifier and Type Field and Description static doubleEThe natural logarithm.static doubleFOUR_PIFour time the ratio of the circumference of a circle to its diameter.static doubleHALF_PIHalf the ratio of the circumference of a circle to its diameter.static doubleInfinityInfinity.static doubleLOG10The natural logarithm of ten.static doubleLOG2The natural logarithm of two.static doubleNaNNot-A-Number.static doublePIThe ratio of the circumference of a circle to its diameter.static doublePI_SQUAREstatic doubleSQRT2The square root of two.static doubleTWO_PITwice the ratio of the circumference of a circle to its diameter.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static doubleabs(double d)Returns the absolute value of the specifieddoubleargument.static floatabs(float f)Returns the absolute value of the specifiedfloatargument.static intabs(int i)Returns the absolute value of the specifiedintargument.static longabs(long l)Returns the absolute value of the specifiedlongargument.static doubleacos(double x)Returns the arc cosine of the specified value, in the range of 0.0 through pi.static doubleasin(double x)Returns the arc sine of the specified value, in the range of -pi/2 through pi/2.static doubleatan(double x)Returns the arc tangent of the specified value, in the range of -pi/2 through pi/2.static doubleatan2(double y, double x)Returns the angle theta such that(x == cos(theta)) && (y == sin(theta)).static doubleceil(double x)Returns the smallest (closest to negative infinity)doublevalue that is not less than the argument and is equal to a mathematical integer.static doublecos(double radians)Returns the trigonometric cosine of the specified angle in radians.static doublecosh(double x)Returns the hyperbolic cosine of x.static doubleexp(double x)Returnseraised to the specified power.static doublefloor(double x)Returns the largest (closest to positive infinity)doublevalue that is not greater than the argument and is equal to a mathematical integer.static doublelog(double x)Returns the natural logarithm (basee) of the specified value.static doublelog10(double x)Returns the decimal logarithm of the specified value.static doublemax(double x, double y)Returns the greater of twodoublevalues.static floatmax(float x, float y)Returns the greater of twofloatvalues.static intmax(int x, int y)Returns the greater of twointvalues.static longmax(long x, long y)Returns the greater of twolongvalues.static doublemin(double x, double y)Returns the smaller of twodoublevalues.static floatmin(float x, float y)Returns the smaller of twofloatvalues.static intmin(int x, int y)Returns the smaller of twointvalues.static longmin(long x, long y)Returns the smaller of twolongvalues.static doublepow(double x, double y)Returns the value of the first argument raised to the power of the second argument.static doublerandom()Returns a random number between zero and one.static intrandomInt(int min, int max)Returns a pseudo randomintvalue in the range[min, max].static doublerem(double x, double y)Returns the remainder of the division of the specified two arguments.static longround(double d)Returns the closestlongto the specified argument.static intround(float f)Returns the closestintto the specified argument.static doublesin(double radians)Returns the trigonometric sine of the specified angle in radians.static doublesinh(double x)Returns the hyperbolic sine of x.static doublesqrt(double x)Returns the positive square root of the specified value.static doubletan(double radians)Returns the trigonometric tangent of the specified angle in radians.static doubletanh(double x)Returns the hyperbolic tangent of x.static doubletoDegrees(double radians)Converts an angle in radians to degrees.static doubletoDouble(long mantissa, int n)Returns the bestdoubleapproximation of the specifiedlongmantissa multiplied by a power of 10 (scientific notation).static doubletoRadians(double degrees)Converts an angle in degrees to radians.
-
-
-
Field Detail
-
E
public static final double E
The natural logarithm.- See Also:
- Constant Field Values
-
PI
public static final double PI
The ratio of the circumference of a circle to its diameter.- See Also:
- Constant Field Values
-
HALF_PI
public static final double HALF_PI
Half the ratio of the circumference of a circle to its diameter.- See Also:
- Constant Field Values
-
TWO_PI
public static final double TWO_PI
Twice the ratio of the circumference of a circle to its diameter.- See Also:
- Constant Field Values
-
FOUR_PI
public static final double FOUR_PI
Four time the ratio of the circumference of a circle to its diameter.- See Also:
- Constant Field Values
-
PI_SQUARE
public static final double PI_SQUARE
- See Also:
- Constant Field Values
-
LOG2
public static final double LOG2
The natural logarithm of two.- See Also:
- Constant Field Values
-
LOG10
public static final double LOG10
The natural logarithm of ten.- See Also:
- Constant Field Values
-
SQRT2
public static final double SQRT2
The square root of two.- See Also:
- Constant Field Values
-
NaN
public static final double NaN
Not-A-Number.- See Also:
- Constant Field Values
-
Infinity
public static final double Infinity
Infinity.- See Also:
- Constant Field Values
-
-
Method Detail
-
randomInt
public static int randomInt(int min, int max)Returns a pseudo randomintvalue in the range[min, max].- Parameters:
min- the minimum value inclusive.max- the maximum value inclusive.- Returns:
- a pseudo random number in the range
[min, max].
-
toRadians
public static double toRadians(double degrees)
Converts an angle in degrees to radians.- Parameters:
degrees- the angle in degrees.- Returns:
- the specified angle in radians.
-
toDegrees
public static double toDegrees(double radians)
Converts an angle in radians to degrees.- Parameters:
radians- the angle in radians.- Returns:
- the specified angle in degrees.
-
sqrt
public static double sqrt(double x)
Returns the positive square root of the specified value.- Parameters:
x- the value.- Returns:
java.lang.Math.sqrt(x)
-
rem
public static double rem(double x, double y)Returns the remainder of the division of the specified two arguments.- Parameters:
x- the dividend.y- the divisor.- Returns:
x - round(x / y) * y
-
ceil
public static double ceil(double x)
Returns the smallest (closest to negative infinity)doublevalue that is not less than the argument and is equal to a mathematical integer.- Parameters:
x- the value.- Returns:
java.lang.Math.ceil(x)
-
floor
public static double floor(double x)
Returns the largest (closest to positive infinity)doublevalue that is not greater than the argument and is equal to a mathematical integer.- Parameters:
x- the value.- Returns:
java.lang.Math.ceil(x)
-
sin
public static double sin(double radians)
Returns the trigonometric sine of the specified angle in radians.- Parameters:
radians- the angle in radians.- Returns:
java.lang.Math.sin(radians)
-
cos
public static double cos(double radians)
Returns the trigonometric cosine of the specified angle in radians.- Parameters:
radians- the angle in radians.- Returns:
java.lang.Math.cos(radians)
-
tan
public static double tan(double radians)
Returns the trigonometric tangent of the specified angle in radians.- Parameters:
radians- the angle in radians.- Returns:
java.lang.Math.tan(radians)
-
asin
public static double asin(double x)
Returns the arc sine of the specified value, in the range of -pi/2 through pi/2.- Parameters:
x- the value whose arc sine is to be returned.- Returns:
- the arc sine in radians for the specified value.
-
acos
public static double acos(double x)
Returns the arc cosine of the specified value, in the range of 0.0 through pi.- Parameters:
x- the value whose arc cosine is to be returned.- Returns:
- the arc cosine in radians for the specified value.
-
atan
public static double atan(double x)
Returns the arc tangent of the specified value, in the range of -pi/2 through pi/2.- Parameters:
x- the value whose arc tangent is to be returned.- Returns:
- the arc tangent in radians for the specified value.
- See Also:
- Inverse Tangent -- from MathWorld
-
atan2
public static double atan2(double y, double x)Returns the angle theta such that(x == cos(theta)) && (y == sin(theta)).- Parameters:
y- the y value.x- the x value.- Returns:
- the angle theta in radians.
-
sinh
public static double sinh(double x)
Returns the hyperbolic sine of x.- Parameters:
x- the value for which the hyperbolic sine is calculated.- Returns:
(exp(x) - exp(-x)) / 2
-
cosh
public static double cosh(double x)
Returns the hyperbolic cosine of x.- Parameters:
x- the value for which the hyperbolic cosine is calculated.- Returns:
(exp(x) + exp(-x)) / 2
-
tanh
public static double tanh(double x)
Returns the hyperbolic tangent of x.- Parameters:
x- the value for which the hyperbolic tangent is calculated.- Returns:
(exp(2 * x) - 1) / (exp(2 * x) + 1)
-
exp
public static double exp(double x)
Returnseraised to the specified power.- Parameters:
x- the exponent.- Returns:
ex- See Also:
- Exponential Function -- from MathWorld
-
log
public static double log(double x)
Returns the natural logarithm (basee) of the specified value.- Parameters:
x- the value greater than0.0.- Returns:
- the value y such as
ey == x
-
log10
public static double log10(double x)
Returns the decimal logarithm of the specified value.- Parameters:
x- the value greater than0.0.- Returns:
- the value y such as
10y == x
-
pow
public static double pow(double x, double y)Returns the value of the first argument raised to the power of the second argument.- Parameters:
x- the base.y- the exponent.- Returns:
xy
-
round
public static int round(float f)
Returns the closestintto the specified argument.- Parameters:
f- thefloatvalue to be rounded to aint- Returns:
- the nearest
intvalue.
-
round
public static long round(double d)
Returns the closestlongto the specified argument.- Parameters:
d- thedoublevalue to be rounded to along- Returns:
- the nearest
longvalue.
-
random
public static double random()
Returns a random number between zero and one.- Returns:
- a
doublegreater than or equal to0.0and less than1.0.
-
abs
public static int abs(int i)
Returns the absolute value of the specifiedintargument.- Parameters:
i- theintvalue.- Returns:
ior-i
-
abs
public static long abs(long l)
Returns the absolute value of the specifiedlongargument.- Parameters:
l- thelongvalue.- Returns:
lor-l
-
abs
public static float abs(float f)
Returns the absolute value of the specifiedfloatargument.- Parameters:
f- thefloatvalue.- Returns:
for-f
-
abs
public static double abs(double d)
Returns the absolute value of the specifieddoubleargument.- Parameters:
d- thedoublevalue.- Returns:
dor-d
-
max
public static int max(int x, int y)Returns the greater of twointvalues.- Parameters:
x- the first value.y- the second value.- Returns:
- the larger of
xandy.
-
max
public static long max(long x, long y)Returns the greater of twolongvalues.- Parameters:
x- the first value.y- the second value.- Returns:
- the larger of
xandy.
-
max
public static float max(float x, float y)Returns the greater of twofloatvalues.- Parameters:
x- the first value.y- the second value.- Returns:
- the larger of
xandy.
-
max
public static double max(double x, double y)Returns the greater of twodoublevalues.- Parameters:
x- the first value.y- the second value.- Returns:
- the larger of
xandy.
-
min
public static int min(int x, int y)Returns the smaller of twointvalues.- Parameters:
x- the first value.y- the second value.- Returns:
- the smaller of
xandy.
-
min
public static long min(long x, long y)Returns the smaller of twolongvalues.- Parameters:
x- the first value.y- the second value.- Returns:
- the smaller of
xandy.
-
min
public static float min(float x, float y)Returns the smaller of twofloatvalues.- Parameters:
x- the first value.y- the second value.- Returns:
- the smaller of
xandy.
-
min
public static double min(double x, double y)Returns the smaller of twodoublevalues.- Parameters:
x- the first value.y- the second value.- Returns:
- the smaller of
xandy.
-
toDouble
public static double toDouble(long mantissa, int n)Returns the bestdoubleapproximation of the specifiedlongmantissa multiplied by a power of 10 (scientific notation).- Parameters:
mantissa- the mantissa aslong.n- the power of 10 exponent.- Returns:
mantissaÃ10n
-
-
DMelt 3.0 © DataMelt by jWork.ORG