Package cds.healpix.common.math
Class Math
java.lang.Object
cds.healpix.common.math.Math
Utility 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
FieldsModifier and TypeFieldDescriptionstatic final double
static final double
static final double
static final double
static final double
static final double
static final double
static final double
static final double
static final double
static final double
static final double
static final double
static final double
static final double
static final double
static final double
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic double
abs
(double a) static double
acos
(double a) static double
asin
(double a) static double
asinc
(double a) Returns the inverse of the cardinal sine function of the given argument, i.e.static double
asincP
(double a) Same asasinc(double)
but assuming the argument is positive.static double
atan2
(double y, double x) static double
atanh
(double x) Returns tanh-1(x), i.e.static double
cos
(double a) static boolean
isFinite
(double v) static double
log
(double x) 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).static double
pow
(double a, double b) 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 = 0static int
roots
(double q0, double q1, double q2, double q3, double[] result) static long
round
(double a) static int
round
(float a) static double
signum
(double a) static double
sin
(double a) static double
sinc
(double a) Returns the cardinal sine function of the given angle, i.e.static double
sincP
(double a) Same assinc(double)
but assuming the argument is positive.static double
sqrt
(double angleRadians) 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)).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).static double
tan
(double a) static double
tanh
(double x) static double
toDegrees
(double a) static double
toRadians
(double a)
-
Field Details
-
EPSILON
public static final double EPSILON- See Also:
-
ONE_THIRD
public static final double ONE_THIRD- See Also:
-
ONE_FOURTH
public static final double ONE_FOURTH- See Also:
-
PI
public static final double PI- See Also:
-
HALF_PI
public static final double HALF_PI- See Also:
-
PI_OVER_FOUR
public static final double PI_OVER_FOUR- See Also:
-
TWO_PI
public static final double TWO_PI- See Also:
-
ONE_OVER_PI
public static final double ONE_OVER_PI- See Also:
-
ONE_OVER_2PI
public static final double ONE_OVER_2PI- See Also:
-
TWO_OVER_PI
public static final double TWO_OVER_PI- See Also:
-
FOUR_OVER_PI
public static final double FOUR_OVER_PI- See Also:
-
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
-
-
Constructor Details
-
Math
public Math()
-
-
Method Details
-
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)
-