SSJ
V. 1.1.9.

umontreal.iro.lecuyer.util
Class Num

java.lang.Object
  extended by umontreal.iro.lecuyer.util.Num

public class Num
extends Object

This class provides a few constants and some methods to compute numerical quantities such as factorials, combinations, gamma functions, and so on.


Field Summary
static int DBL_DIG
          Number of decimal digits of precision in a double.
static double DBL_EPSILON
          Difference between 1.0 and the smallest double greater than 1.0.
static int DBL_MAX_10_EXP
          Largest int x such that 10x is representable (approximately) as a double.
static int DBL_MAX_EXP
          Largest int x such that 2x-1 is representable (approximately) as a double.
static double DBL_MIN
          Smallest normalized positive floating-point double.
static int DBL_MIN_EXP
          Smallest int x such that 2x-1 is representable (approximately) as a normalised double.
static double EBASE
          The constant e.
static double ILN2
          The values of 1/ln 2.
static double IRAC2
          The value of 1/(2)1/2.
static double LN2
          The values of ln 2.
static double MAXINTDOUBLE
          Largest integer n0 = 253 such that any integer n <= n0 is represented exactly as a double.
static double MAXTWOEXP
          Powers of 2 up to MAXTWOEXP are stored exactly in the array TWOEXP.
static double RAC2
          The value of (2)1/2.
static double[] TWOEXP
          This table contains the powers of two, precomputed.
 
Method Summary
static double besselK025(double x)
          Returns the value of K1/4(x), where Ka is the modified Bessel's function of the second kind.
static double[][] calcMatStirling(int m, int n)
          Computes and returns the Stirling numbers of the second kind
static double combination(int n, int s)
          Returns the number of different combinations of s objects amongst n.
static double evalCheby(double[] S, int N, double x)
          Evaluates a series of Chebyshev polynomials Tj, at point x∈[- 1,  1].
static double factorial(int n)
          Returns the value of n factorial.
static double lnFactorial(int n)
          Returns the value of the natural logarithm of n factorial.
static double lnGamma(double x)
          Returns the natural logarithm of the gamma function evaluated at x.
static double log1p(double x)
          Returns a value equivalent to log(1 + x) accurate also for small x.
static double log2(double x)
          Returns log2(x).
static double multMod(double a, double s, double c, double m)
          Returns (as + c)mod m.
static int multMod(int a, int s, int c, int m)
          Returns (as + c)mod m.
static long multMod(long a, long s, long c, long m)
          Returns (as + c)mod m.
static double volumeSphere(double p, int t)
          Returns the volume V of a sphere of radius 1 in t dimensions using the norm Lp.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DBL_EPSILON

public static final double DBL_EPSILON
Difference between 1.0 and the smallest double greater than 1.0.

See Also:
Constant Field Values

DBL_MAX_EXP

public static final int DBL_MAX_EXP
Largest int x such that 2x-1 is representable (approximately) as a double.

See Also:
Constant Field Values

DBL_MIN_EXP

public static final int DBL_MIN_EXP
Smallest int x such that 2x-1 is representable (approximately) as a normalised double.

See Also:
Constant Field Values

DBL_MAX_10_EXP

public static final int DBL_MAX_10_EXP
Largest int x such that 10x is representable (approximately) as a double.

See Also:
Constant Field Values

DBL_MIN

public static final double DBL_MIN
Smallest normalized positive floating-point double.

See Also:
Constant Field Values

DBL_DIG

public static final int DBL_DIG
Number of decimal digits of precision in a double.

See Also:
Constant Field Values

EBASE

public static final double EBASE
The constant e.

See Also:
Constant Field Values

RAC2

public static final double RAC2
The value of (2)1/2.

See Also:
Constant Field Values

IRAC2

public static final double IRAC2
The value of 1/(2)1/2.

See Also:
Constant Field Values

LN2

public static final double LN2
The values of ln 2.

See Also:
Constant Field Values

ILN2

public static final double ILN2
The values of 1/ln 2.

See Also:
Constant Field Values

MAXINTDOUBLE

public static final double MAXINTDOUBLE
Largest integer n0 = 253 such that any integer n <= n0 is represented exactly as a double.

See Also:
Constant Field Values

MAXTWOEXP

public static final double MAXTWOEXP
Powers of 2 up to MAXTWOEXP are stored exactly in the array TWOEXP.

See Also:
Constant Field Values

TWOEXP

public static final double[] TWOEXP
This table contains the powers of two, precomputed. One has TWOEXP[i]= 2i for i = 0,..., 64.

Method Detail

log2

public static double log2(double x)
Returns log2(x).

Parameters:
x - the value for which the logarithm must be computed
Returns:
the value of log2(x)

log1p

public static double log1p(double x)
Returns a value equivalent to log(1 + x) accurate also for small x.

Parameters:
x - the argument of the function
Returns:
the value of log(1 + x)

factorial

public static double factorial(int n)
Returns the value of n factorial.

Parameters:
n - the integer for which the factorial must be computed
Returns:
the value of n!

lnFactorial

public static double lnFactorial(int n)
Returns the value of the natural logarithm of n factorial. Gives at least 16 decimals of precision (relative error < 0.5×10-15).

Parameters:
n - the integer for which the log-factorial has to be computed
Returns:
the natural logarithm of n factorial

lnGamma

public static double lnGamma(double x)
Returns the natural logarithm of the gamma function evaluated at x. Gives 16 decimals of precision. Restriction: implemented only for x > 0.

Parameters:
x - the value for which the lnGamma function must be computed
Returns:
the natural logarithm of the gamma function

combination

public static double combination(int n,
                                 int s)
Returns the number of different combinations of s objects amongst n. Uses an algorithm that prevents overflows (when computing factorials), if possible.

Parameters:
n - total number of objects
s - number of chosen objects on a combination
Returns:
the number of different combinations of s objects amongst n

calcMatStirling

public static double[][] calcMatStirling(int m,
                                         int n)
Computes and returns the Stirling numbers of the second kind

Parameters:
m - number of rows of the allocated matrix
n - number of columns of the allocated matrix
Returns:
the matrix of Stirling numbers

volumeSphere

public static double volumeSphere(double p,
                                  int t)
Returns the volume V of a sphere of radius 1 in t dimensions using the norm Lp. It is given by the formula

V = ([2Γ(1 + 1/p)]t)/Γ(1 + t/p),        p > 0,

where Γ is the gamma function. The case of the sup norm L∞ is obtained by choosing p = 0. Restrictions: p >=  0 and t >= 1.

Parameters:
p - index of the used norm
t - number of dimensions
Returns:
the volume of a sphere

evalCheby

public static double evalCheby(double[] S,
                               int N,
                               double x)
Evaluates a series of Chebyshev polynomials Tj, at point x∈[- 1,  1]. It uses the method of Clenshaw, i.e., computes and returns

y = S0/2 + ∑j=1NSjTj(x).

Parameters:
S - coefficients of the polynomials
N - largest degree of polynomials
x - the parameter of the Tj functions
Returns:
the value of a series of Chebyshev polynomials Tj.

besselK025

public static double besselK025(double x)
Returns the value of K1/4(x), where Ka is the modified Bessel's function of the second kind. The relative error on the returned value is less than 0.5×10-6 for x > 10-300. .

Parameters:
x - value at which the function is calculated
Returns:
the value of K1/4(x)

multMod

public static int multMod(int a,
                          int s,
                          int c,
                          int m)
Returns (as + c)mod m. Restriction: assumes that a, c, s < m.

Parameters:
a - first term of the product
s - second term of the product
c - shift factor
m - the used modulo
Returns:
the value of (as + c)mod m.

multMod

public static long multMod(long a,
                           long s,
                           long c,
                           long m)
Returns (as + c)mod m. Uses the class ArithmeticMod. Restriction: assumes that a, c, s < m.

Parameters:
a - first term of the product
s - second term of the product
c - shift factor
m - the used modulo
Returns:
the value of (as + c)mod m.

multMod

public static double multMod(double a,
                             double s,
                             double c,
                             double m)
Returns (as + c)mod m. Restriction: assumes that a, s, c are < m and a, s, c, m are < 235.

Parameters:
a - first term of the product
s - second term of the product
c - shift factor
m - the used modulo
Returns:
the value of (as + c)mod m.

SSJ
V. 1.1.9.

To submit a bug or ask questions, send an e-mail to Pierre L'Ecuyer.