Michael Thomas Flanagan's Java Scientific Library

Fmath Class:      Mathematical Functions and Physical Constants

     

Last update: 13 August 2011                                                                                                                              PERMISSION TO COPY
Main Page of Michael Thomas Flanagan's Java Scientific Library

This class supplements the Java class Math (java.lang.Math ).
This supplementary class, Fmath, contains:
NOTE!
The one-dimensional arrays methods have been improved and moved to the ArrayMaths class.
The conversion of physical units and copying 1D, 2D and 3D arrays and copying an object methods have now been incorporated into the Conv class.
The write arrays to screen methods have now been incorporated into the PrintToScreen class.
Those methods that were part of the Fmath class will be retained in Fmath for compatibility purposes. Their old documentation can now be found on FmathDeprecatedMethods.

import directive: import flanagan.math.Fmath;

SUMMARY OF METHODS AND OF CONSTANTS

METHODS
Trigonometric
Functions

(additional
to those in
java.lang.Math)
Cotangent public static double cot(double a)
Secant public static double sec(double a)
Cosecant public static double csc(double a)
Exsecant public static double exsec(double a)
Versine public static double vers(double a)
Coversine public static double covers(double a)
Haversine public static double hav(double a)
Unnormalised sinc (Unnormalised sine cardinal) public static double sinc(double a)
Normalised sinc (Normalised sine cardinal) public static double nsinc(double a)
Hyperbolic sine public static double sinh(double a)
Hyperbolic cosine public static double cosh(double a)
Hyperbolic tangent public static double tanh(double a)
Hyperbolic cotangent public static double coth(double a)
Hyperbolic secant public static double sech(double a)
Hyperbolic cosecant public static double csch(double a)
Inverse cotangent public static double acot(double a)
public static double acot2(double a, double b)
Inverse secant public static double asec(double a)
Inverse cosecant public static double acsc(double a)
Inverse exsecant public static double aexsec(double a)
Inverse versine public static double avers(double a)
Inverse coversine public static double acovers(double a)
Inverse haversine public static double ahav(double a)
Inverse hyperbolic sine public static double asinh(double a)
Inverse hyperbolic cosine public static double acosh(double a)
Inverse hyperbolic tangent public static double atanh(double a)
Inverse hyperbolic cotangent public static double acoth(double a)
Inverse hyperbolic secant public static double asech(double a)
Inverse hyperbolic cosecant public static double acsch(double a)
Angles of a triangle public static double angle(double sideAC, double sideBC, double sideAB)
public static double angle(double xAtA, double yAtA, double xAtB, double yAtB, double xAtC, double yAtC)
Sine public static double sin(double sideAC, double sideBC, double sideAB)
public static double sin(double xAtA, double yAtA, double xAtB, double yAtB, double xAtC, double yAtC)
public static double sin(double radians)
Inverse sine public static double asin(double a)
Cosine public static double cos(double sideAC, double sideBC, double sideAB)
public static double cos(double xAtA, double yAtA, double xAtB, double yAtB, double xAtC, double yAtC)
public static double cos(double radians)
Inverse cosine public static double acos(double a)
Tangent public static double tan(double sideAC, double sideBC, double sideAB)
public static double tan(double xAtA, double yAtA, double xAtB, double yAtB, double xAtC, double yAtC)
public static double atan(double radians)
Inverse tangent public static double atan(double a)
public static double atan2(double a, double a)
Hypotenuse public static double hypot(double a, double b)
public static float hypot(float a, float b)
Factorials Factorial public static int factorial(int n)
public static long factorial(long n)
public static BigInteger factorial(BigInteger n)
public static double factorial(double n)
public static BigDecimal factorial(BigDecimal n)
log(factorial) public static double logFactorial(int n)
public static double logFactorial(long n)
public static double logFactorial(double n)
Logarithms Log to base b public static double log(double x, double b)
public static double log(double x, int b)
public static float log(float x, float b)
public static float log(float x, int b)
Log to base 2 public static double log2(double x)
public static float log2(float x)
public static double antilog2(double x)
public static float antilog2(float x)
Log to base 10 public static double log10(double x)
public static float log10(float x)
public static double antilog10(double x)
public static float antilog10(float x)
Log to base e public static double log(double x)
public static float log(float x)
public static double antilog(double x)
public static float antilog(float x)
Square   public static double square(double a)
public static float square(float a)
public static BigDecimal square(BigDecimal a)
public static int square(int a)
public static long square(long a)
public static BigInteger square(BigInteger a)
Sign   public static double sign(double a)
public static float sign(float a)
public static int sign(int a)
Check precision   public static int checkPrecision(double x)
public static int checkPrecision(float x)
Truncate mantissa to n places   public static double truncate(double x, int n)
public static float truncate(float x, int n)
See Complex Class for truncation of Complex numbers.
See Phasor Class for truncation of Phasor numbers.
See ErrorProp Class for truncation of ErrorProp numbers.
See ComplexErrorProp Class for truncation of ComplexErrorProp numbers
Logical tests Compare (equal, less or greater than) public static int compare(double x, double y)
public static int compare(float x, float y)
public static int compare(long x, long y)
public static int compare(int x, int y)
public static int compare(short x, short y)
public static int compare(byte x, byte y)
Compare 1D arrays
(true if identical)
public static boolean compare(double[] array1, double[] array2)
public static boolean compare(float[] array1, float[] array2)
public static boolean compare(long[] array1, long[] array2)
public static boolean compare(int[] array1, int[] array2)
Infinity public static boolean isInfinity(double x)
public static boolean isInfinity(float x)
Positive Infinity public static boolean isPlusInfinity(double x)
public static boolean isPlusInfinity(float x)
Negative Infinity public static boolean isMinusInfinity(double x)
public static boolean isMinusInfinity(float x)
NaN (not-a-number) public static boolean isNaN(double x)
public static boolean isNaN(float x)
Equalities public static boolean isEqual(double x, double y)
public static boolean isEqual(float x, float y)
public static boolean isEqual(int x, int y)
public static boolean isEqual(char x, char y)
public static boolean isEqual(String x, String y)
Equalities within limits public static boolean isEqualWithinLimits(double x, double y, double limit)
public static boolean isEqualWithinLimits(float x, float y, float limit)
public static boolean isEqualWithinLimits(long x, long y, long limit)
public static boolean isEqualWithinLimits(int x, int y, int limit)
public static boolean isEqualWithinLimits(BigDecimal x, BigDecimal y, BigDecimal limit)
public static boolean isEqualWithinLimits(BigInteger x, BigInteger y, BigInteger limit)
Equalities within a percentage of the mean public static boolean isEqualWithinPerCent(double x, double y, double percentage)
public static boolean isEqualWithinPerCent(float x, float y, float percentage)
public static boolean isEqualWithinPerCent(long x, long y, double percentage)
public static boolean isEqualWithinPerCent(long x, long y, long percentage)
public static boolean isEqualWithinPerCent(int x, int y, double percentage)
public static boolean isEqualWithinPerCent(int x, int y, int percentage)
public static boolean isEqualWithinPerCent(BigDecimal x, BigDecimal y, BigDecimal percentage)
public static boolean isEqualWithinPerCent(BigInteger x, BigInteger y, BigDecimal percentage)
public static boolean isEqualWithinPerCent(BigInteger x, BigInteger y, BigInteger percentage)
Integer public static boolean isInteger(double x)
public static boolean isInteger(Double x)
public static boolean isInteger(float x)
public static boolean isInteger(Float x)
public static boolean isInteger(BigDecimal x)
public static boolean isInteger(double[] x)
public static boolean isInteger(Double[] x)
public static boolean isInteger(float[] x)
public static boolean isInteger(Float[] x)
public static boolean isInteger(BigDecimal[] x)
Even number public static boolean isEven(int x)
public static boolean isEven(float x)
public static boolean isEven(double x)
Odd number public static boolean isOdd(int x)
public static boolean isOdd(float x)
public static boolean isOdd(double x)
Is a year a leap year? public static boolean leapYear(int year)


CONSTANTS
Constants Avagadro constant [mol-1] public static final double N_AVAGADRO = 6.0221419947e23;
Boltzmann constant [J K-1] public static final double K_BOLTZMANN = 1.380650324e-23;
Planck constant [J s] public static final double H_PLANCK = 6.6260687652e-34;
Reduced Planck constant [J s] public static final double H_PLANCK_RED = H_PLANCK/(2*PI);
Speed of light in vacuo [m s-1] public static final double C_LIGHT = 2.99792458e8;
Molar gas constant [J K-1 mol-1] public static final double R_GAS = 8.31447215;
Faraday constant [C mol-1] public static final double F_FARADAY = 9.6485341539e4;
Absolute zero [Celsius] public static final double T_ABS = -273.15;
Charge on the electron [C] public static final double Q_ELECTRON = -1.60217646263e-19;
Rest mass of the electron [kg] public static final double M_ELECTRON = 9.1093818872e-31;
Rest mass of the proton [kg] public static final double M_PROTON = 1.6726215813e-27;
Rest mass of the neutron [kg] public static final double M_NEUTRON = 1.6749271613e-27;
Electrical permittivity of free space [F m-1] public static final double EPSILON_0 = 8.854187817e-12;
Magnetic permeability of free space [H m-1 (N A-2)] public static final double MU_0 = PI*4e-7;
Characteristic impedance of free space [Ohms] public static final double ETA_0 = MU_0*C_LIGHT;
Euler's constant (gamma)   public static final double EULER_CONSTANT_GAMMA = 0.5772156649015627;
π (the ratio of the circumference
of a circle to its diameter)
  public static final double PI = Math.PI;        [3.141592653589793]
e (the base of the natural logarithms)   public static final double E = Math.E;        [2.718281828459045]



PHYSICAL AND MATHEMATICAL CONSTANTS

The values of the physical constants and conversion factors are taken from the CODATA Recommended Values of the Fundamental Physical Constants, 1998, Journal of Physical and Chemical Reference Data, Vol. 28, N0. 6, 1999 and Reviews of Modern Physics, Vol 72, No. 2, 2000.

Avagadro constant [mol-1]
public static final double N_AVAGADRO = 6.0221419947e23;
Boltzmann constant [J K-1]
public static final double K_BOLTZMANN = 1.380650324e-23;
Planck constant [J s]
public static final double H_PLANCK = 6.6260687652e-34;
Reduced Planck constant [J s]
public static final double H_PLANCK_RED = H_PLANCK/(2*PI);
Speed of light in vacuo [m s-1]
public static final double C_LIGHT = 2.99792458e8;
Molar gas constant [K-1 mol-1]
public static final double R_GAS = 8.31447215;
Faraday constant [C mol-1]
public static final double F_FARADAY = 9.6485341539e4;
Absolute zero [Celsius]
public static final double T_ABS = -273.15;
Charge on the electron [C]
public static final double Q_ELECTRON = -1.60217646263e-19;
Rest mass of the electron [kg]
public static final double M_ELECTRON = 9.1093818872e-31;
Rest mass of the proton [kg]
public static final double M_PROTON = 1.6726215813e-27;
Rest mass of the neutron [kg]
public static final double M_NEUTRON = 1.6749271613e-27;
Electrical permittivity of free space [F m-1]
public static final double EPSILON_0 = 8.854187817e-12;
Magnetic permeability of free space [ 4π10-7 H m-1 (N A-2)]
public static final double MU_0 = Math.PI*4.0e-7;
Characteristic impedance of free space, ηo [Ohms]
public static final double ETA_0 = MU_0*C_LIGHT;

Euler's constant (gamma)
public static final double EULER_CONSTANT_GAMMA = 0.5772156649015627;

π (the ratio of the circumference of a circle to its diameter)
Fmath.PI is included as a convenience and is equated to the java.lang.Math, Math.PI       [3.141592653589793]
e (the base of the natural logarithms)
Fmath.E is included as a convenience and is equated to the java.lang.Math, Math.E         [2.718281828459045]


Example of general usage:                      double x = Fmath.CONSTANT;
where CONSTANT is the constant, e.g. K_BOLTZMANN



METHODS

ADDITIONAL TRIGONOMETRIC FUNCTIONS
These functions supplement the main list of trigonometric functions which may be found in java.lang.Math.
The java.lang.Math functions sin, cos, tan, sinh, cosh and tanh have also been included in this Fmath library for completeness and, in this Fmath library, sin, cos and tan may also take, as their arguments, the lengths of the sides of a triangle or the coordinates of the apices of a triangle (see below). Their inverses have also been included and differ from the java.lang.math methods in that the argument is checked as to whether it lies within the allowed limits for that function and an Illegal Argument Exception is thrown if it does not. The java library returns NaN in such cases.

General Usage:                     double x = Fmath.funct(y);
where funct is the trigonometric function, e.g. sinh

Cotangent
public static double cot(double a)
Secant
public static double sec(double a)
Cosecant
public static double csc(double a)
Exsecant [exsec(a) = sec(a) - 1]
public static double exsec(double a)
Versine [vers(a) = 1 - cos(a)]
public static double vers(double a)
Coversine [covers(a) = 1 - sin(a)]
public static double covers(double a)
Haversine [hav(a) = 0.5vers(a)]
public static double hav(double a)
Unnormalised sinc (unnormalised sine cardinal) [unnormalised sinc(a) = sin(a)/a]
public static double sinc(double a)
Normalised sinc (normalised sine cardinal) [normalised sinc(a) = sin(πa)/(πa)]
public static double nsinc(double a)
Hyperbolic sine
public static double sinh(double a)
Hyperbolic cosine
public static double cosh(double a)
Hyperbolic tangent
public static double tanh(double a)
Hyperbolic cotangent
public static double coth(double a)
Hyperbolic secant
public static double sech(double a)
Hyperbolic cosecant
public static double csch(double a)
Inverse cotangent
public static double acot(double a)
public static double acot2(double a, double b)
Inverse secant
public static double asec(double a)
Inverse cosecant
public static double acsc(double a)
Inverse exsecant
public static double aexsec(double a)
Inverse versine
public static double avers(double a)
Inverse coversine
public static double acovers(double a)
Inverse haversine
public static double ahav(double a)
Inverse hyperbolic sine
public static double asinh(double a)
Inverse hyperbolic cosine
public static double acosh(double a)
Inverse hyperbolic tangent
public static double atanh(double a)
Inverse hyperbolic cotangent
public static double acoth(double a)
Inverse hyperbolic secant
public static double asech(double a)
Inverse hyperbolic cosecant
public static double acsch(double a)



ANGLES OF A TRIANGLE
public static double angle(double sideAC, double sideBC, double sideAB)
public static double angle(double xAtA, double yAtA, double xAtB, double yAtB, double xAtC, double yAtC)
Usage:                      theta = Fmath.angle(sideAC, sideBC, sideAB);
Given the triangle

returns the angle, θ in radians, where sideAC, sideBC and sideAB, are the lengths of the sides AC, BC, and AB respectively.

Usage:                      theta = Fmath.angle(xAtA, yAtA, xAtB, yAtB, xAtC, yAtC);
Returns the angle, θ in radians, where xAtA and yAtA are the x and y coordinates at apex A, xAtB and yAtB are the x and y coordinates at apex B and xAtC and yAtC are the x and y coordinates at apex C in Figure 1 above.

SINE
public static double sin(double sideAc, double sideBc, double sideAB)
public static double sin(double xAtA, double yAtA, double xAtB, double yAtB, double xAtC, double yAtC)
public static double sin(double theta)
Usage:                      sinTheta = Fmath.sin(sideAC, sideBC, sideAB);
Returns the sine of the angle, θ shown in Figure 1 above, where sideAC, sideBC and sideAB, are the lengths of the sides AC, BC, and AB respectively.

Usage:                      sinTheta = Fmath.sin(xAtA, yAtA, xAtB, yAtB, xAtC, yAtC);
Returns the sine of the angle, θ in shown in Figure 1 above, where xAtA and yAtA are the x and y coordinates at apex A, xAtB and yAtB are the x and y coordinates at apex B and xAtC and yAtC are the x and y coordinates at apex C.

Usage:                      sinTheta = Fmath.sin(theta);
Returns the sine of the angle, theta radians.

Inverse sine
public static double asin(double a)
Usage:                      theta = Fmath.asin(arg);
Returns the inverse sine of arg in radians. If arg is less than -1 or greater than 1 an Illegal Argument Exception is thrown. The java.lang.math method, asin(arg), returns NaN in such circumstances.

COSINE
public static double cos(double sideAc, double sideBc, double sideAB)
public static double cos(double xAtA, double yAtA, double xAtB, double yAtB, double xAtC, double yAtC)
public static double cos(double theta)
Usage:                      cosTheta = Fmath.cos(sideAC, sideBC, sideAB);
Returns the cosine of the angle, θ shown in Figure 1 above, where sideAC, sideBC and sideAB, are the lengths of the sides AC, BC, and AB respectively.

Usage:                      cosTheta = Fmath.cos(xAtA, yAtA, xAtB, yAtB, xAtC, yAtC);
Returns the cosine of the angle, θ in shown in Figure 1 above, where xAtA and yAtA are the x and y coordinates at apex A, xAtB and yAtB are the x and y coordinates at apex B and xAtC and yAtC are the x and y coordinates at apex C.

Usage:                      cosTheta = Fmath.cos(theta);
Returns the cosine of the angle, theta radians.

Inverse cosine
public static double acos(double a)
Usage:                      theta = Fmath.acos(arg);
Returns the inverse cosine of arg in radians. If arg is less than -1 or greater than 1 an Illegal Argument Exception is thrown. The java.lang.math method, acos(arg), returns NaN in such circumstances.

TANGENT
public static double tan(double sideAc, double sideBc, double sideAB)
public static double tan(double xAtA, double yAtA, double xAtB, double yAtB, double xAtC, double yAtC)
public static double tan(double theta)
Usage:                      tanTheta = Fmath.tan(sideAC, sideBC, sideAB);
Returns the tangent of the angle, θ shown in Figure 1 above, where sideAC, sideBC and sideAB, are the lengths of the sides AC, BC, and AB respectively.

Usage:                      tanTheta = Fmath.tan(xAtA, yAtA, xAtB, yAtB, xAtC, yAtC);
Returns the tangent of the angle, θ in shown in Figure 1 above, where xAtA and yAtA are the x and y coordinates at apex A, xAtB and yAtB are the x and y coordinates at apex B and xAtC and yAtC are the x and y coordinates at apex C.

Usage:                      tanTheta = Fmath.tan(theta);
Returns the tangent of the angle, theta radians.

Inverse tangent
public static double atan(double a)
public static double atan2(double a, double a)
Usage:                      theta = Fmath.atan(arg);
Returns the inverse tangent of arg in radians.
Usage:                      theta = Fmath.atan(arg1, arg2);
Returns the inverse tangent of arg1/arg2 in radians.



HYPOTENUSE
Returns the length of the hypotenuse of a and b, i.e. sqrt(a*a+b*b).
This method avoids unecessary overflow or underflow. Equivalent to Math.hypot(a, b)
public static double hypot(double a, double b)
public static float hypot(float a, float b)
Usage:                      d = Fmath.hypot(a, b);



LOGARITHMS


Logarithm to a given base
public static double log(double x, double b)
public static double log(double x, int b)
public static float log(float x, float b)
public static float log(float x, int b)
Usage:                      log = Fmath.log(x, b);
Returns the logarithm to base b of x.



Logarithm to base 2
public static double log2(double x)
public static float log2(float x)
Usage:                      log = Fmath.log2(x);
Returns the logarithm to base 2 of x.



Base 2 antilogarithm
public static double antilog2(double x)
public static float antilog2(float x)
Usage:                      antilog = Fmath.antilog2(x);
Returns the base 2 antilogarithm of x, i.e. 2x.



Logarithm to base 10
public static double log10(double x)
public static float log10(float x)
Usage:                      log = Fmath.log10(x);
Returns the logarithm to base 10 of x. This method is identical to Math.log10(x).



Base 10 antilogarithm
public static double antilog10(double x)
public static float antilog10(float x)
Usage:                      antilog = Fmath.antilog10(x);
Returns the base 10 antilogarithm of x, i.e. 10x.



Logarithm to base e
public static double log10(double x)
public static float log(float x)
Usage:                      log = Fmath.log(x);
Returns the logarithm to base e of x. This method is identical to Math.log(x).



Base e antilogarithm
public static double antilog(double x)
public static float antilog(float x)
Usage:                      antilog = Fmath.antilog(x);
Returns the base 2 antilogarithm of x, i.e. ex. This method is identical to Math.exp(x).



SQUARE
public static double square(double a)
public static float square(float a)
public static BigDecimal square(BigDecimal a)
public static int square(int a)
public static long square(long a)
public static BigInteger square(BigInteger a)
Usage:                      d = Fmath.square(a);
Returns the square of a.



FACTORIALS AND LOG(FACTORIALS)
Factorials
public static int factorial(int n)
public static long factorial(long n)
public static BigInteger factorial(BigInteger n)
public static double factorial(double n)
public static BigDecimal factorial(BigDecimal n)
Usage:                      f = Fmath.factorial(n);
Returns the factorial of n.
If n = type int the range of n is limited by integer maximum size to 0 to 12.
If n = type long the range of n is limited by long integer maximum size to 0 to 20.
If n = type double avoids integer overflow but n must still be, numerically, an integer and rounding errors will make the returned value an approximation for n>21.

Log to base e of a factorial
public static double logFactorial(int n)
public static double logFactorial(long n)
public static double logFactorial(double n)
Usage:                      lf = Fmath.logFactorial(n);
The argument, n, may be of type int, long or double, though if of type double, must still be, numerically, an integer. The log(factorial) is returned as type double and rounding errors may make the returned value an approximation.



CHECK PRECISION
public static int checkPrecision(double x)
public static int checkPrecision(float x)
Usage:                      prec = Fmath.checkPrecision(x);
Returns the precision of the number, x, i.e. the number of places in the mantissa, e.g, if x = 5.189427 a value of 6 will be returned to prec.



TRUNCATE MANTISSA TO N PLACES
public static double truncate(double x, int n)
public static float truncate(float x, int n)
Usage:                      xt = Fmath.truncate(x, n);
Returns the value of x with its mantissa rounded to n decimal places, e.g truncate(-3.234724e-25, 3) returns -3.235e-25, truncate(1.999999, 4) returns 2.0000. The variable x may be double or float. If the argument indicating the number of places before truncation, i.e. n in the above example, is any negative integer, the variable to be truncated, i.e. x in the above example, is returned without truncation. This method can be useful in outputting data.
See Complex Class for truncation of complex numbers.
See ErrorProp Class for truncation of ErrorProp numbers.
See ComplexErrorProp Class for truncation of ComplexErrorProp numbers.



SIGN
public static double sign(double a)
public static float sign(float a)
public static int sign(int a)
public static long sign(long a)
Usage:                      d = Fmath.sign(a);
Returns, as a double, +1.0 if the sign of a is positive and returns -1.0 if the sign of a is negative. Differs from Math.signum(x) in that Fmath.sign(x) returns +1.0 if x is equal to 0.0 whereas the signum function, Math.signum(x), returns 0.0 if x is equal to 0.0. The argument may be double, float, int or long.



LOGICAL TESTS
[See Complex Class for logical tests on Complex numbers]

Check whether two variables are equal or which is greater if they are not
public static int compare(double x, double y)
public static int compare(float x, float y)
public static int compare(long x, long y)
public static int compare(int x, int y)
public static int compare(short x, short y)
public static int compare(byte x, byte y)
Usage:                      test = Fmath.compare(x, y);
Returns  -1 if x is less than y
Returns   0 if x equals y
Returns +1 if x is greater than y
The two arguments may be double, float, long, int, short or byte BUT both must be of the same type.

Check whether two one dimensional arrays are identical
public static boolean compare(double[] array1, double[] array2)
public static boolean compare(float[] array1, float[] array2)
public static boolean compare(long[] array1, long[] array2)
public static boolean compare(int[] array1, int[] array2)
Usage:                      test = Fmath.compare(array1, array2);
Returns true if array1 and array2 are identical, returns false if they are not.
The two arguments may be double[], float[], long[] or int[] BUT both must be of the same type.

Check whether a variable is equal to either positive infinity or negative infinity
public static boolean isInfinity(double x)
public static boolean isInfinity(float x)
Usage:                      test = Fmath.isInfinity(x);
Returns true if the argument (x in the above example) is equal to either plus infinity (Double.POSITIVE_INFINITY or Float.POSITIVE_INFINITY) or minus infinity (Double.NEGATIVE_INFINITY or Float.NEGATIVE_INFINITY), e.g. the result of either the operation 1.0/0.0 or -1.0/0.0. Returns false if not. The argument may be double or float.

Check whether a variable is equal to positive infinity
public static boolean isPlusInfinity(double x)
public static boolean isPlusInfinity(float x)
Usage:                      test = Fmath.isPlusInfinity(x);
Returns true if the argument (x in the above example) is equal to plus infinity (Double.POSITIVE_INFINITY or Float.POSITIVE_INFINITY), e.g. the result of the operation 1.0/0.0. Returns false if not. The argument may be double or float.

Check whether a variable is equal to negative infinity
public static boolean isMinusInfinity(double x)
public static boolean isMinusInfinity(float x)
Usage:                      test = Fmath.isMinusInfinity(x);
Returns true if the argument (x in the above example) is equal to minus infinity (Double.NEGATIVE_INFINITY or Float.NEGATIVE_INFINITY), e.g. the result of the operation -1.0/0.0. Returns false if not. The argument may be double or float.

Check whether a variable is NaN (not-a-number)
public static boolean isNaN(double x)
public static boolean isNaN(float x)
Usage:                      test = Fmath.isNaN(x);
Returns true if the argument (x in the above example) is NaN (not-a-number) (Double.NaN or Float.NaN), e.g. the result of the operation 0.0/0.0. Returns false if not. The argument may be double or float.

Check whether two variables are equal
public static boolean isEqual(double x, double y)
public static boolean isEqual(float x, float y)
public static boolean isEqual(int x, int y)
public static boolean isEqual(char x, char y)
public static boolean isEqual(String x, String y)
Usage:                      test = Fmath.isEqual(x,y);
Returns true if the arguments (x and y in the above example) are equal. Returns false if not. The two arguments may be double, float, int, char or String. If the arguments are double, float or Complex the method works for plus infinity (Double. POSITIVE_INFINTY or Float.POSITIVE_INFINTY), minus infinity (Double.NEGATIVE_INFINITY or Float.NEGATIVE_INFINITY) or NaN (Double.NaN or Float.NaN). NB! true is returned if x and y are both NaN [i.e. this method violates the IEEE Specification 754 but is consistent with the Java.lang.Object.equals() method. However x==y returns false if both x and y are NaN.]

Check whether two variables are equal within limits
public static boolean isEqualWithinLimits(double x, double y, double limit)
public static boolean isEqualWithinLimits(float x, float y, float limit)
public static boolean isEqualWithinLimits(int x, int y, int limit)
public static boolean isEqualWithinLimits(long x, long y, long limit)
public static boolean isEqualWithinLimits(BigDecimal x, BigDecimal y, BigDecimal limit)
public static boolean isEqualWithinLimits(BigInteger x, BigInteger y, BigInteger limit)
Usage:                      test = Fmath.isEqualWithinLimits(x,y,limit);
Returns true if the absolute value of the difference between x and y (in the above example) is less than or equal to the limit. Returns false if not. The arguments may be double, float, long, int, BigDecimal or BigInteger.

Check whether two variables are equal within a given percentage of their mean
public static boolean isEqualWithinPerCent(double x, double y, double percentage)
public static boolean isEqualWithinPerCent(float x, float y, float percentage)
public static boolean isEqualWithinPerCent(int x, int y, double percentage)
public static boolean isEqualWithinPerCent(int x, int y, int percentage)
public static boolean isEqualWithinPerCent(long x, long y, double percentage)
public static boolean isEqualWithinPerCent(long x, long y, long percentage)
public static boolean isEqualWithinPerCent(BigDecimal x, BigDecimal y, BigDecimal percentage)
public static boolean isEqualWithinPerCent(BigInteger x, BigInteger y, BigDecimal percentage)
public static boolean isEqualWithinPerCent(BigInteger x, BigInteger y, BigInteger percentage)
Usage:                      test = Fmath.isEqualWithinPerCent(x,y,percentage);
Returns true if the absolute value of the difference between x and y (in the above example) is less than or equal to a given percentage of their mean. The given percentage is supplied as percentage in the above example. Returns false if not. The arguments may be double, float, long, int, BigDecimal or BigInteger and for int and long arguments the percentage may also be supplied as a double and in the case of BigInteger the percentage may also be supplied as a BigDecimal.

Check whether a variable is, arithmetically, an integer
public static boolean isInteger(double x)
public static boolean isInteger(float x)
public static boolean isInteger(Double x)
public static boolean isInteger(Float x)
public static boolean isInteger(BigDecimal x)
public static boolean isInteger(double[] xx)
public static boolean isInteger(float[] xx)
public static boolean isInteger(Double[] xx)
public static boolean isInteger(Float[] xx)
public static boolean isInteger(BigDecimal[] xx)
Usage:                      test = Fmath.isInteger(x);
Returns true if the argument (x in the above example) is, arithmetically, an integer. Returns false if not. The argument may be double, float, Double, Float or BigDecimal.

Usage:                      test = Fmath.isInteger(xx);
Returns true if every element of the array argument (xx in the above example) is, arithmetically, an integer. Returns false if one or more elements of the array, xx, is not, arithmetically, an integer. The argument, xx, may be an array of doubles, floats, Doubles, Floats or BigDecimals.

Check whether a variable is an even number
public static boolean isEven(int x)
public static boolean isEven(float x)
public static boolean isEven(double x)
Usage:                      test = Fmath.isEven(x);
Returns true if the arguments (x in the above example) is an even number. Returns false if not. The argument may be int, float or double but if float or double it must, nonetheless, arithmetically, be an integer.

Check whether a variable is an odd number
public static boolean isOdd(int x)
public static boolean isOdd(float x)
public static boolean isOdd(double x)
Usage:                      test = Fmath.isOdd(x);
Returns true if the argument (x in the above example) is an odd number. Returns false if not. The argument may be int, float or double but if float or double it must, nonetheless, arithmetically, be an integer.

Check whether a year is a leap year
public static boolean leapYear(int year)
Usage:                      test = Fmath.leapYear(year);
Returns true if the year (argument year in the above example) is a leap year. Returns false if not.



1-D ARRAYS
FIND THE NEAREST ARRAY ELEMENT TO A GIVEN VALUE
NOTE! One dimensional array search methods have now been incorporated into the class ArrayMaths. Those that were part of the Fmath class will be retained for compatibility purposes. They are documented on this FmathDeprecatedMethods.
The ArrayMaths class contains a more extensive list of one dimensional array search methods.

FIND THE MINIMUM DIFFERENCE BETWEEN THE ARRAY ELEMENTS
NOTE! One dimensional array search methods have now been incorporated into the class ArrayMaths. Those that were part of the Fmath class will be retained for compatibility purposes. They are documented on this FmathDeprecatedMethods.
The ArrayMaths class contains a more extensive list of one dimensional array search methods.

FIND THE MAXIMUM DIFFERENCE BETWEEN THE ARRAY ELEMENTS
NOTE! One dimensional array search methods have now been incorporated into the class ArrayMaths. Those that were part of the Fmath class will be retained for compatibility purposes. They are documented on this FmathDeprecatedMethods.
The ArrayMaths class contains a more extensive list of one dimensional array search methods.

WRITE AN ARRAY TO SCREEN
NOTE! Write arrays to screen methods have now been incorporated into the class PrintToScreen. Those that were part of the Fmath class will also be retained for compatibility purposes. They are documented on this FmathDeprecatedMethods.
The PrintToScreen class contains a more extensive list of write to screen methods.
RECAST ARRAY TYPE
NOTE! One dimensional array conversion methods have now been incorporated into the class ArrayMaths. Those that were part of the Fmath class will be retained for compatibility purposes. They are documented on this FmathDeprecatedMethods.
The ArrayMaths class contains a more extensive list of one dimensional array conversion methods.

ARRAY MINIMUM
NOTE! One dimensional array minimum methods have now been incorporated into the class ArrayMaths. Those that were part of the Fmath class will be retained for compatibility purposes. They are documented on this FmathDeprecatedMethods.
The ArrayMaths class contains a more extensive list of one dimensional array methods.

ARRAY MAXIMUM
NOTE! One dimensional array maximum methods have now been incorporated into the class ArrayMaths. Those that were part of the Fmath class will be retained for compatibility purposes. They are documented on this FmathDeprecatedMethods.
The ArrayMaths class contains a more extensive list of one dimensional array methods.

REVERSE AN ARRAY ORDER
NOTE! 1D array reversal method has now been incorporated into the class ArrayMaths. Those that were part of the Fmath class will also be retained for compatibility purposes. They are documented on this FmathDeprecatedMethods.
The ArrayMaths class contains a more extensive list of reversal methods.

OBTAIN ABSOLUTE VALUES OF THE ARRAY ELEMENTS
NOTE! 1D array absulate value method has now been incorporated into the class
ArrayMaths. Those that were part of the Fmath class will also be retained for compatibility purposes. They are documented on this FmathDeprecatedMethods.
The ArrayMaths class contains a more extensive list of absolute value methods.

TAKING THE LOG TO BASE 10 OF EACH ARRAY ELEMENT
NOTE! 1D array log10 method has now been incorporated into the class ArrayMaths. Those that were part of the Fmath class will also be retained for compatibility purposes. They are documented on this FmathDeprecatedMethods.
The ArrayMaths class contains a more extensive list of log methods.

TAKING THE LOG TO BASE e OF EACH ARRAY ELEMENT
NOTE! 1D array log method has now been incorporated into the class ArrayMaths. Those that were part of the Fmath class will also be retained for compatibility purposes. They are documented on this FmathDeprecatedMethods.
The ArrayMaths class contains a more extensive list of log methods.

TAKING THE SQUARE ROOT OF EACH ARRAY ELEMENT
NOTE! 1D array square root method has now been incorporated into the class ArrayMaths. Those that were part of the Fmath class will also be retained for compatibility purposes. They are documented on this FmathDeprecatedMethods.
The ArrayMaths class contains a more extensive list of square root methods.

RAISE OF EACH ARRAY ELEMENT TO A POWER
NOTE! 1D array power method has now been incorporated into the class ArrayMaths. Those that were part of the Fmath class will also be retained for compatibility purposes. They are documented on this FmathDeprecatedMethods.
The ArrayMaths class contains a more extensive list of power methods.

OBTAIN THE SUM OF ALL THE ARRAY ELEMENTS
NOTE! 1D array summation method has now been incorporated into the class ArrayMaths. Those that were part of the Fmath class will also be retained for compatibility purposes. They are documented on this FmathDeprecatedMethods.
The ArrayMaths class contains a more extensive list of summation methods.

OBTAIN THE PRODUCT OF ALL THE ARRAY ELEMENTS
NOTE! 1D array product method has now been incorporated into the class ArrayMaths. Those that were part of the Fmath class will also be retained for compatibility purposes. They are documented on this FmathDeprecatedMethods.
The ArrayMaths class contains a more extensive list of product methods.

MULTIPLY THE ARRAY ELEMENTS BY A CONSTANT
NOTE! 1D array multiplication methods have now been incorporated into the class ArrayMaths. Those that were part of the Fmath class will also be retained for compatibility purposes. They are documented on this FmathDeprecatedMethods.
The ArrayMaths class contains a more extensive list of multiplication methods.

INVERT ALL ARRAY ELEMENTS
NOTE! 1D array inversion methods have now been incorporated into the class ArrayMaths. Those that were part of the Fmath class will also be retained for compatibility purposes. They are documented on this FmathDeprecatedMethods.
The ArrayMaths class contains a more extensive list of inversion methods.

SORTING
NOTE! 1D array sort methods have now been incorporated into the class ArrayMaths. Those that were part of the Fmath class will also be retained for compatibility purposes. They are documented on this FmathDeprecatedMethods.
The ArrayMaths class contains a more extensive list of sort methods.

CONCATENATE TWO ARRAYS
NOTE! 1D array concatenate methods have now been incorporated into the class ArrayMaths. Those that were part of the Fmath class will also be retained for compatibility purposes. They are documented on this FmathDeprecatedMethods.
The ArrayMaths class contains a more extensive list of concatenate methods.

FIND THE INDEX OF THE FIRST ARRAY ELEMENT EQUAL TO A GIVEN VALUE
NOTE! 1D array search methods have now been incorporated into the class ArrayMaths. Those that were part of the Fmath class will also be retained for compatibility purposes. They are documented on this FmathDeprecatedMethods.
The ArrayMaths class contains a more extensive list of search methods.

FIND THE INDICES OF ALL ARRAY ELEMENTS EQUAL TO A GIVEN VALUE
NOTE! 1D array search methods have now been incorporated into the class ArrayMaths. Those that were part of the Fmath class will also be retained for compatibility purposes. They are documented on this FmathDeprecatedMethods.
The ArrayMaths class contains a more extensive list of search methods.



PHYSICAL UNIT CONVERSION FUNCTIONS

NOTE! Physical Unit Conversion functions have now been incorporated into the class Conv. Those that were part of the Fmath class will also be retained for compatibility purposes. They are documented on this FmathDeprecatedMethods.
The Conv class contains a more extensive list of conversion methods.


OTHER CLASSES USED BY THIS CLASS

This class uses the following classes in this library:



PERMISSION TO COPY

Permission to use, copy and modify this software and its documentation for NON-COMMERCIAL purposes is granted, without fee, provided that an acknowledgement to the author, Dr Michael Thomas Flanagan at www.ee.ucl.ac.uk/~mflanaga, appears in all copies and associated documentation or publications.

Use for COMMERCIAL purposes is not permitted

Public listing of the source codes on the internet is not permitted.

Redistribution of the source codes or of the flanagan.jar file is not permitted.

Redistribution in binary form of all or parts of these classes is not permitted.

Dr Michael Thomas Flanagan makes no representations about the suitability or fitness of the software for any or for a particular purpose. Dr Michael Thomas Flanagan shall not be liable for any damages suffered as a result of using, modifying or distributing this software or its derivatives.



This page was prepared by Dr Michael Thomas Flanagan