Class Math

java.lang.Object
cds.healpix.common.math.Math

public final class Math extends Object
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

    Fields
    Modifier and Type
    Field
    Description
    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
     
    static final double
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static 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 as asinc(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 = 0
    static 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 as sinc(double) but assuming the argument is positive.
    static double
    sqrt(double angleRadians)
     
    static double
    To be used when sin(a) is near from 1 and a high precision is needed on sqrt(1 - sin(a)).
    static double
    Same as sqrtOfOneMinusSin(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)
     

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • 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 as sqrtOfOneMinusSin(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 as sinc(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 as asinc(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^0
      q1 - coefficient of x^1
      q2 - coefficient of x^2
      result - 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)