Class ExtraMath
- java.lang.Object
-
- jsci.maths.AbstractMath
-
- jsci.maths.ExtraMath
-
public final class ExtraMath extends AbstractMath
The extra math library. Provides extra functions not in java.lang.Math class. This class cannot be subclassed or instantiated because all methods are static.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static doubleacosh(double x)Returns the inverse hyperbolic cosine of adoublevalue.static doubleacoth(double x)Returns the inverse hyperbolic cotangent of adoublevalue.static doubleacsch(double x)Returns the inverse hyperbolic cosecant of adoublevalue.static doubleasech(double x)Returns the inverse hyperbolic secant of adoublevalue.static doubleasinh(double x)Returns the inverse hyperbolic sine of adoublevalue.static doubleatanh(double x)Returns the inverse hyperbolic tangent of adoublevalue.static doublebinomial(double n, double k)Returns the binomial coefficient (n k).static intbinomial(int n, int k)Returns the binomial coefficient (n k).static doublecosh(double x)Returns the hyperbolic cosine of a double.static doublecoth(double x)Returns the hyperbolic cotangent of adoublevalue.static doublecsch(double x)Returns the hyperbolic cosecant of adoublevalue.static doublefactorial(double x)Returns the factorial.static doublehypot(double x, double y)Returns sqrt(x2+y2).static doublelog10(double x)Returns the base 10 logarithm of a double.static doublelogFactorial(double x)Returns the natural logarithm of the factorial.static intpow(int a, int b)Returns ab.static intpow2(int a)Returns 2a.static doublerandom(double min, double max)Returns a random number within a specified range.static doubleround(double x, int significant)Rounds a number to so many significant figures.static doublesech(double x)Returns the hyperbolic secant of adoublevalue.static intsign(double x)Returns the sign of a number.static doublesinh(double x)Returns the hyperbolic sine of a double.static doubletanh(double x)Returns the hyperbolic tangent of a double.
-
-
-
Method Detail
-
round
public static double round(double x, int significant)Rounds a number to so many significant figures.- Parameters:
x- a number to be rounded.significant- number of significant figures to round to.
-
random
public static double random(double min, double max)Returns a random number within a specified range.
-
sign
public static int sign(double x)
Returns the sign of a number.- Returns:
- 1 if x>0.0, -1 if x<0.0, else 0.
-
hypot
public static double hypot(double x, double y)Returns sqrt(x2+y2).
-
pow
public static int pow(int a, int b)Returns ab.- Parameters:
a- an integer.b- a positive integer.
-
pow2
public static int pow2(int a)
Returns 2a.- Parameters:
a- a positive integer.
-
factorial
public static double factorial(double x)
Returns the factorial. (Wrapper for the gamma function).- Parameters:
x- a double.- See Also:
SpecialMath.gamma(double)
-
logFactorial
public static double logFactorial(double x)
Returns the natural logarithm of the factorial. (Wrapper for the log gamma function).- Parameters:
x- a double.- See Also:
SpecialMath.logGamma(double)
-
binomial
public static int binomial(int n, int k)Returns the binomial coefficient (n k). Uses Pascal's recursion formula.- Parameters:
n- an integer.k- an integer.
-
binomial
public static double binomial(double n, double k)Returns the binomial coefficient (n k). Uses gamma functions.- Parameters:
n- a double.k- a double.
-
log10
public static double log10(double x)
Returns the base 10 logarithm of a double.- Parameters:
x- a double.
-
sinh
public static double sinh(double x)
Returns the hyperbolic sine of a double.- Parameters:
x- a double.
-
cosh
public static double cosh(double x)
Returns the hyperbolic cosine of a double.- Parameters:
x- a double.
-
tanh
public static double tanh(double x)
Returns the hyperbolic tangent of a double.- Parameters:
x- a double.
-
coth
public static double coth(double x)
Returns the hyperbolic cotangent of adoublevalue.The identity is:
coth(x) = (ex + e-x)/(ex - e-x), in other words, cosh(x)/sinh(x).
Special cases:
- If the argument is NaN, then the result is NaN.
- If the argument is zero, then the result is an infinity with the same sign as the argument.
- If the argument is positive infinity, then the result is
+1.0. - If the argument is negative infinity, then the result is
-1.0.
- Parameters:
x- The number whose hyperbolic cotangent is sought- Returns:
- The hyperbolic cotangent of
x
-
csch
public static double csch(double x)
Returns the hyperbolic cosecant of adoublevalue.The identity is:
csch(x) = (2/(ex - e-x), in other words, 1/sinh(x).
Special cases:
- If the argument is NaN, then the result is NaN.
- If the argument is zero, then the result is an infinity with the same sign as the argument.
- If the argument is positive infinity, then the result is
+0.0. - If the argument is negative infinity, then the result is
-0.0.
- Parameters:
x- The number whose hyperbolic cosecant is sought- Returns:
- The hyperbolic cosecant of
x
-
sech
public static double sech(double x)
Returns the hyperbolic secant of adoublevalue.The identity is:
sech(x) = (2/(ex + e-x), in other words, 1/cosh(x).
Special cases:
- If the argument is NaN, then the result is NaN.
- If the argument is an infinity (positive or negative), then the result is
+0.0.
- Parameters:
x- The number whose hyperbolic secant is sought- Returns:
- The hyperbolic secant of
x
-
asinh
public static double asinh(double x)
Returns the inverse hyperbolic sine of adoublevalue.The identity is:
asinh(x) = ln(x + sqrt(x2 + 1))
Special cases:
- If the argument is NaN, then the result is NaN.
- If the argument is infinite, then the result is an infinity with the same sign as the argument.
- If the argument is zero, then the result is a zero with the same sign as the argument.
- Parameters:
x- The number whose inverse hyperbolic sine is sought- Returns:
- The inverse hyperbolic sine of
x
-
acosh
public static double acosh(double x)
Returns the inverse hyperbolic cosine of adoublevalue. Note that cosh(+/-acosh(x)) = x; this function arbitrarily returns the positive branch.The identity is:
acosh(x) = ln(x +/- sqrt(x2 - 1))
Special cases:
- If the argument is NaN or less than one, then the result is NaN.
- If the argument is a positive infinity, then the result is (positive) infinity.
- If the argument is one, then the result is (positive) zero.
- Parameters:
x- The number whose inverse hyperbolic cosine is sought- Returns:
- The inverse hyperbolic cosine of
x
-
atanh
public static double atanh(double x)
Returns the inverse hyperbolic tangent of adoublevalue.The identity is:
atanh(x) = (1/2)*ln((1 + x)/(1 - x))
Special cases:
- If the argument is NaN, an infinity, or has a modulus of greater than one, then the result is NaN.
- If the argument is plus or minus one, then the result is infinity with the same sign as the argument.
- If the argument is zero, then the result is a zero with the same sign as the argument.
- Parameters:
x- A double specifying the value whose inverse hyperbolic tangent is sought- Returns:
- A double specifying the inverse hyperbolic tangent of x
-
acoth
public static double acoth(double x)
Returns the inverse hyperbolic cotangent of adoublevalue.The identity is:
acoth(x) = (1/2)*ln((x + 1)/(x - 1))
Special cases:
- If the argument is NaN or a modulus of less than one, then the result is NaN.
- If the argument is an infinity, then the result is zero with the same sign as the argument.
- If the argument is plus or minus one, then the result is infinity with the same sign as the argument.
- Parameters:
x- The number whose inverse hyperbolic cotangent is sought- Returns:
- The inverse hyperbolic cotangent of
x
-
acsch
public static double acsch(double x)
Returns the inverse hyperbolic cosecant of adoublevalue.The identity is:
acsch(x) = ln((1 - sqrt(1 + x2))/x) for x < 0;
acsch(x) = ln((1 + sqrt(1 + x2))/x) for x > 0.
Special cases:
- If the argument is NaN, then the result is NaN.
- If the argument is an infinity, then the result is zero with the same sign as the argument.
- If the argument is zero, then the result is infinity with the same sign as the argument.
- Parameters:
x- The number whose inverse hyperbolic cosecant is sought- Returns:
- The inverse hyperbolic cosecant of
x
-
asech
public static double asech(double x)
Returns the inverse hyperbolic secant of adoublevalue. Note that sech(+/-asech(x)) = x; this function arbitrarily returns the positive branch.The identity is:
asech(x) = ln((1 + sqrt(1 - x2))/x).
Special cases:
- If the argument is NaN, less than zero, or greater than one, then the result is NaN.
- If the argument is zero, then the result is infinity with the same sign as the argument.
- Parameters:
x- The number whose hyperbolic secant is sought- Returns:
- The hyperbolic secant of
x
-
-
DMelt 3.0 © DataMelt by jWork.ORG