Package com.imsl.math
Class JMath
java.lang.Object
com.imsl.math.JMath
Pure Java implementation of the standard java.lang.Math class.
This Java code is based on C code in the package fdlibm,
which can be obtained from www.netlib.org.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic doubleabs(double x) Returns the absolute value of adouble.static floatabs(float x) Returns the absolute value of afloat.static intabs(int x) Returns the absolute value of anint.static longabs(long x) Returns the absolute value of along.static doubleacos(double x) Returns the inverse (arc) cosine of adouble.static doubleasin(double x) Returns the inverse (arc) sine of adouble.static doubleatan(double x) Returns the inverse (arc) tangent of adouble.static doubleatan2(double y, double x) Returns the angle corresponding to a Cartesian point.static doubleceil(double x) Returns the value of adoublerounded toward positive infinity to an integral value.static doublecos(double x) Returns the cosine of adouble.static doubleexp(double x) Returns the exponential of adouble.static doublefloor(double x) Returns the value of adoublerounded toward negative infinity to an integral value.static doubleIEEEremainder(double x, double p) Returns the IEEE remainder from x divided by p.static doublelog(double x) Returns the natural logarithm of adouble.static doublemax(double x, double y) Returns the larger of twodoubles.static floatmax(float x, float y) Returns the larger of twofloats.static intmax(int x, int y) Returns the larger of twoints.static longmax(long x, long y) Returns the larger of twolongs.static doublemin(double x, double y) Returns the smaller of twodoubles.static floatmin(float x, float y) Returns the smaller of twofloats.static intmin(int x, int y) Returns the smaller of twoints.static longmin(long x, long y) Returns the smaller of twolongs.static doublepow(double x, double y) Returns x to the power y.static doublerandom()Returns a random number from a uniform distribution.static doublerint(double x) Returns the value of adoublerounded toward the closest integral value.static longround(double x) Returns thelongclosest to a givendouble.static intround(float x) Returns the integer closest to a givenfloat.static doublesin(double x) Returns the sine of adouble.static doublesqrt(double x) Returns the square root of adouble.static doubletan(double x) Returns the tangent of adouble.
-
Field Details
-
PI
public static final double PI -
E
public static final double E
-
-
Method Details
-
abs
public static int abs(int x) Returns the absolute value of anint.- Parameters:
x- anint- Returns:
- an
intrepresenting \(|x|\).
-
abs
public static long abs(long x) Returns the absolute value of along.- Parameters:
x- along- Returns:
- a
longrepresenting \(|x|\).
-
abs
public static float abs(float x) Returns the absolute value of afloat.- Parameters:
x- afloat- Returns:
- a
floatrepresenting \(|x|\).
-
abs
public static double abs(double x) Returns the absolute value of adouble.- Parameters:
x- adouble- Returns:
- a
doublerepresenting \(|x|\).
-
min
public static int min(int x, int y) Returns the smaller of twoints.- Parameters:
x- aninty- anint- Returns:
- an
intrepresenting the smaller of x and y
-
min
public static long min(long x, long y) Returns the smaller of twolongs.- Parameters:
x- alongy- along- Returns:
- a
long, the smaller of x and y
-
min
public static float min(float x, float y) Returns the smaller of twofloats.- Parameters:
x- afloaty- afloat- Returns:
- a
float, the smaller of x and y. This function considers -0.0f to be less than 0.0f.
-
min
public static double min(double x, double y) Returns the smaller of twodoubles.- Parameters:
x- adoubley- adouble- Returns:
- a
double, the smaller of x and y. This function considers -0.0 to be less than 0.0.
-
max
public static int max(int x, int y) Returns the larger of twoints.- Parameters:
x- aninty- anint- Returns:
- an
int, the larger of x and y
-
max
public static long max(long x, long y) Returns the larger of twolongs.- Parameters:
x- alongy- along- Returns:
- a
long, the larger of x and y
-
max
public static float max(float x, float y) Returns the larger of twofloats.- Parameters:
x- afloaty- afloat- Returns:
- a
float, the larger of x and y. This function considers -0.0f to be less than 0.0f.
-
max
public static double max(double x, double y) Returns the larger of twodoubles.- Parameters:
x- adoubley- adouble- Returns:
- a
double, the larger of x and y. This function considers -0.0 to be less than 0.0.
-
round
public static int round(float x) Returns the integer closest to a givenfloat.- Parameters:
x- afloat- Returns:
- the
intclosest to x
-
round
public static long round(double x) Returns thelongclosest to a givendouble.- Parameters:
x- adouble- Returns:
- the
longclosest to x
-
random
public static double random()Returns a random number from a uniform distribution.- Returns:
- a
doublerepresenting a random number from a uniform distribution
-
ceil
public static double ceil(double x) Returns the value of adoublerounded toward positive infinity to an integral value.- Parameters:
x- adouble- Returns:
- the smallest
double, not less than x, that is an integral value
-
floor
public static double floor(double x) Returns the value of adoublerounded toward negative infinity to an integral value.- Parameters:
x- adouble- Returns:
- the smallest
double, not greater than x, that is an integral value
-
rint
public static double rint(double x) Returns the value of adoublerounded toward the closest integral value.- Parameters:
x- adouble- Returns:
- the
doubleclosest to x that is an integral value
-
IEEEremainder
public static double IEEEremainder(double x, double p) Returns the IEEE remainder from x divided by p. The IEEE remainder is \(x \% p = x - [x / p] \times p\) as if in infinite precise arithmetic, where [x/p] is the (infinite bit) integer nearest x/p (in half way case choose the even one).- Parameters:
x- adouble, the dividendp- adouble, the divisor- Returns:
- a
doublerepresenting the remainder computed according to the IEEE 754 standard.
-
sqrt
public static double sqrt(double x) Returns the square root of adouble.- Parameters:
x- adouble- Returns:
- a
doublerepresenting the square root of x
-
exp
public static double exp(double x) Returns the exponential of adouble. Special cases: \(e^{\infty}\) is \(\infty\), \(e^{\rm {NaN}}\) is NaN; \(e^{-\infty}\) is 0, and for finite argument, only \(e^0 = 1\) is exact.- Parameters:
x- adouble.- Returns:
- a
doublerepresenting \(e^x\).
-
log
public static double log(double x) Returns the natural logarithm of adouble.- Parameters:
x- adouble- Returns:
- a
doublerepresenting the natural (base e) logarithm of x
-
sin
public static double sin(double x) Returns the sine of adouble.- Parameters:
x- adouble, assumed to be in radians- Returns:
- a
double, the sine of x
-
cos
public static double cos(double x) Returns the cosine of adouble.- Parameters:
x- adouble, assumed to be in radians- Returns:
- a
double, the cosine of x
-
tan
public static double tan(double x) Returns the tangent of adouble.- Parameters:
x- adouble, assumed to be in radians- Returns:
- a
double, the tangent of x
-
asin
public static double asin(double x) Returns the inverse (arc) sine of adouble.- Parameters:
x- adouble- Returns:
- a
doublerepresenting the angle, in radians, whose sine is x. It is in the range \([-\pi / 2, \pi / 2]\).
-
acos
public static double acos(double x) Returns the inverse (arc) cosine of adouble.- Parameters:
x- adouble- Returns:
- a
doublerepresenting the angle, in radians, whose cosine is x. It is in the range \([0, \pi]\).
-
atan
public static double atan(double x) Returns the inverse (arc) tangent of adouble.- Parameters:
x- adouble- Returns:
- a
doublerepresenting the angle, in radians, whose tangent is x. It is in the range \([-\pi / 2, \pi / 2]\).
-
atan2
public static double atan2(double y, double x) Returns the angle corresponding to a Cartesian point.- Parameters:
x- adouble, the first argumenty- adouble, the second argument- Returns:
- a
doublerepresenting the angle, in radians, the the line from (0,0) to (x,y) makes with the x-axis. It is in the range \([-\pi, \pi]\).
-
pow
public static double pow(double x, double y) Returns x to the power y.- Parameters:
x- adouble, the basey- adouble, the exponent- Returns:
- a
double, x to the power y
-