Package cds.healpix.common.math
Class Math
- java.lang.Object
-
- cds.healpix.common.math.Math
-
public final class Math extends java.lang.ObjectUtility class to easily switch between java.lang.Math and another Math librarie like FastMath, and to define new functions like sinc (sinus cardinal = sin(x) / x). Replace java..lang.Math by org..apache.commons.math3.util.FastMath (using e.g. sed or replaceAll) to use FastMath instead of Math (and vice-versa).- Author:
- F.-X. Pineau
-
-
Field Summary
Fields Modifier and Type Field Description static doubleEPSILONstatic doubleFOUR_OVER_PIstatic doubleHALF_PIstatic doubleLOG2static doubleONE_FOURTHstatic doubleONE_OVER_2PIstatic doubleONE_OVER_PIstatic doubleONE_THIRDstatic doublePIstatic doublePI_OVER_FOURstatic doubleSQRT2static doubleSQRT2_INVstatic doubleSQRT3static doubleSQRT3_INVstatic doubleSQRT6static doubleTWO_OVER_PIstatic doubleTWO_PI
-
Constructor Summary
Constructors Constructor Description Math()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static doubleabs(double a)static doubleacos(double a)static doubleasin(double a)static doubleasinc(double a)Returns the inverse of the cardinal sine function of the given argument, i.e.static doubleasincP(double a)Same asasinc(double)but assuming the argument is positive.static doubleatan2(double y, double x)static doubleatanh(double x)Returns tanh-1(x), i.e.static doublecos(double a)static booleanisFinite(double v)static doublelog(double x)static doubleoneMinusSin(double a)To be used when sin(a) is near from 1 and a high precision is needed on 1 - sin(a).static doublepow(double a, double b)static introots(double q0, double q1, double q2, double[] result)Compute the number of real roots of the quadratic equation: q2*x^2 + q1*x + q0 = 0static introots(double q0, double q1, double q2, double q3, double[] result)static longround(double a)static intround(float a)static doublesignum(double a)static doublesin(double a)static doublesinc(double a)Returns the cardinal sine function of the given angle, i.e.static doublesincP(double a)Same assinc(double)but assuming the argument is positive.static doublesqrt(double angleRadians)static doublesqrtOfOneMinusSin(double a)To be used when sin(a) is near from 1 and a high precision is needed on sqrt(1 - sin(a)).static doublesqrtOfOneMinusSinPC(double a)Same assqrtOfOneMinusSin(double)but limited to angle having a positive cosine (in practice cos(a/2 + PI/2) must be positive).static doubletan(double a)static doubletanh(double x)static doubletoDegrees(double a)static doubletoRadians(double a)
-
-
-
Field Detail
-
EPSILON
public static final double EPSILON
- See Also:
- Constant Field Values
-
ONE_THIRD
public static final double ONE_THIRD
- See Also:
- Constant Field Values
-
ONE_FOURTH
public static final double ONE_FOURTH
- See Also:
- Constant Field Values
-
PI
public static final double PI
- See Also:
- Constant Field Values
-
HALF_PI
public static final double HALF_PI
- See Also:
- Constant Field Values
-
PI_OVER_FOUR
public static final double PI_OVER_FOUR
- See Also:
- Constant Field Values
-
TWO_PI
public static final double TWO_PI
- See Also:
- Constant Field Values
-
ONE_OVER_PI
public static final double ONE_OVER_PI
- See Also:
- Constant Field Values
-
ONE_OVER_2PI
public static final double ONE_OVER_2PI
- See Also:
- Constant Field Values
-
TWO_OVER_PI
public static final double TWO_OVER_PI
- See Also:
- Constant Field Values
-
FOUR_OVER_PI
public static final double FOUR_OVER_PI
- See Also:
- Constant Field Values
-
LOG2
public static final double LOG2
-
SQRT2
public static final double SQRT2
-
SQRT2_INV
public static final double SQRT2_INV
-
SQRT3
public static final double SQRT3
-
SQRT3_INV
public static final double SQRT3_INV
-
SQRT6
public static final double SQRT6
-
-
Method Detail
-
isFinite
public static boolean isFinite(double v)
-
toRadians
public static double toRadians(double a)
-
toDegrees
public static double toDegrees(double a)
-
abs
public static double abs(double a)
-
signum
public static double signum(double a)
-
round
public static int round(float a)
-
round
public static long round(double a)
-
pow
public static double pow(double a, double b)
-
cos
public static double cos(double a)
-
sin
public static double sin(double a)
-
oneMinusSin
public static double oneMinusSin(double a)
To be used when sin(a) is near from 1 and a high precision is needed on 1 - sin(a). Uses formula: 2 * cos(x / 2 + pi/4) Coming from: 1 - sin(x) = sin(pi / 2) - sin(x) = 2 sin(pi / 4 - x / 2) cos(pi / 4 + x / 2) = -2 sin(x / 2 - pi / 4) cos(x / 2 + pi / 4) = -2 sin(x / 2 + pi / 4 - pi / 2) cos(x / 2 + pi / 4) = 2 cos(x / 2 + pi / 4) cos(x / 2 + pi / 4)- Parameters:
a- angle in radians- Returns:
- 1 - sin(a)
-
sqrtOfOneMinusSin
public static double sqrtOfOneMinusSin(double a)
To be used when sin(a) is near from 1 and a high precision is needed on sqrt(1 - sin(a)).oneMinusSin(double).- Parameters:
a- angle in radians HAVING a POSITIVE COSINE.- Returns:
- sqrt(1 - sin(a))
-
sqrtOfOneMinusSinPC
public static double sqrtOfOneMinusSinPC(double a)
Same assqrtOfOneMinusSin(double)but limited to angle having a positive cosine (in practice cos(a/2 + PI/2) must be positive).- Parameters:
a- angle in radians HAVING a POSITIVE COSINE, or more generally, a in [-3pi/2, pi/2].- Returns:
- sqrt(1 - sin(a))
-
tan
public static double tan(double a)
-
sinc
public static double sinc(double a)
Returns the cardinal sine function of the given angle, i.e. sin(x) / x. Precision of 10e-16 on small angles.- Parameters:
a- angle in radians- Returns:
- the cardinal sine function of the given angle, i.e. sin(x) / x.
-
sincP
public static double sincP(double a)
Same assinc(double)but assuming the argument is positive. Precision of 10e-16 on small angles.- Parameters:
a- angle we are looking for the sine, must be > 0.- Returns:
- the cardinal sine function of the given angle, assuming it is positive.
-
acos
public static double acos(double a)
-
asin
public static double asin(double a)
-
asinc
public static double asinc(double a)
Returns the inverse of the cardinal sine function of the given argument, i.e. the inverse of sin(x) / x.- Parameters:
a- argument- Returns:
- the inverse of the cardinal sine function of the given aegument.
-
asincP
public static double asincP(double a)
Same asasinc(double)but assuming the argument is positive.- Parameters:
a- argument- Returns:
- the inverse of the cardinal sine function of the given aegument, assuming the argument is positive.
-
atan2
public static double atan2(double y, double x)
-
tanh
public static double tanh(double x)
-
atanh
public static double atanh(double x)
Returns tanh-1(x), i.e. the inverse function of tanh.- Parameters:
x- argument, in range ]-1, 1[ (NaN returned otherwise)- Returns:
- the hyperbolic inverse tangent of the given argument
-
log
public static double log(double x)
-
sqrt
public static double sqrt(double angleRadians)
-
roots
public static int roots(double q0, double q1, double q2, double[] result)Compute the number of real roots of the quadratic equation: q2*x^2 + q1*x + q0 = 0- Parameters:
q0- coefficient of x^0q1- coefficient of x^1q2- coefficient of x^2result- arrays of size at least 2 storing the real roots (if any)- Returns:
- the number of real roots
-
roots
public static int roots(double q0, double q1, double q2, double q3, double[] result)
-
-