SSJ
V. labo.

umontreal.iro.lecuyer.util
Class Num

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

public class Num
extends Object

Num

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
          .
static double DBL_EPSILON
          .
static int DBL_MAX_10_EXP
          .
static int DBL_MAX_EXP
          .
static double DBL_MIN
          .
static int DBL_MIN_EXP
          .
static double EBASE
          .
static double EULER
          .
static double ILN2
          .
static double IRAC2
          .
static double LN_DBL_MIN
          .
static double LN2
          .
static double MAXINTDOUBLE
          .
static double MAXTWOEXP
          .
static double RAC2
          .
static double[] TEN_NEG_POW
          .
static double[] TWOEXP
          .
 
Method Summary
static double bernoulliPoly(int n, double x)
          .
static double besselK025(double x)
          .
static double[][] calcMatStirling(int m, int n)
          .
static double combination(int n, int s)
          .
static double digamma(double x)
          .
static double erf(double x)
          .
static double erfc(double x)
          .
static double erfcInv(double u)
          .
static double erfInv(double u)
          .
static double evalCheby(double[] a, int n, double x)
          .
static double evalChebyStar(double[] a, int n, double x)
          .
static double expBesselK1(double x, double y)
          .
static double factoPow(int n)
          .
static double factorial(int n)
          .
static double gammaRatioHalf(double x)
          .
static int gcd(int x, int y)
          .
static long gcd(long x, long y)
          [tabb83]
xinteger yinteger the GCD of x and y
static double harmonic(long n)
          .
static double harmonic2(long n)
          .
static double lnBeta(double lam, double nu)
          .
static double lnCombination(int n, int s)
          .
static double lnFactorial(int n)
          .
static double lnFactorial(long n)
          [tabb118]
nargument of the log-factorial natural logarithm of n factorial
static double lnGamma(double x)
          .
static double log2(double x)
          .
static double sumKahan(double[] A, int n)
          .
static double tetragamma(double x)
          .
static double trigamma(double x)
          .
static double volumeSphere(double p, int t)
          .
 
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
. \begin{tabb}Difference between 1.0 and the smallest \texttt{double} greater than 1.0.
 \end{tabb}

See Also:
Constant Field Values

DBL_MAX_EXP

public static final int DBL_MAX_EXP
. \begin{tabb}Largest \texttt{int} $x$\ such that $2^{x-1}$\ is representable
 (approximately) as a \texttt{double}.
 \end{tabb}

See Also:
Constant Field Values

DBL_MIN_EXP

public static final int DBL_MIN_EXP
. \begin{tabb}Smallest \texttt{int} $x$\ such that $2^{x-1}$\ is representable
 (approximately) as a normalised \texttt{double}.
 \end{tabb}

See Also:
Constant Field Values

DBL_MAX_10_EXP

public static final int DBL_MAX_10_EXP
. \begin{tabb}Largest \texttt{int} $x$\ such that $10^x$\ is representable
 (approximately) as a \texttt{double}.
 \end{tabb}

See Also:
Constant Field Values

DBL_MIN

public static final double DBL_MIN
. \begin{tabb}Smallest normalized positive floating-point \texttt{double}.
 \end{tabb}

See Also:
Constant Field Values

LN_DBL_MIN

public static final double LN_DBL_MIN
. \begin{tabb}Natural logarithm of \texttt{DBL\_MIN}.
 \end{tabb}

See Also:
Constant Field Values

DBL_DIG

public static final int DBL_DIG
. \begin{tabb}Number of decimal digits of precision in a \texttt{double}.
 \end{tabb}

See Also:
Constant Field Values

EBASE

public static final double EBASE
. \begin{tabb}The constant $e$.
 \end{tabb}

See Also:
Constant Field Values

EULER

public static final double EULER
. \begin{tabb}The Euler-Mascheroni constant.
 \end{tabb}

See Also:
Constant Field Values

RAC2

public static final double RAC2
. \begin{tabb}The value of $\sqrt{2}$.
 \end{tabb}

See Also:
Constant Field Values

IRAC2

public static final double IRAC2
. \begin{tabb}The value of $1/\sqrt{2}$.
 \end{tabb}

See Also:
Constant Field Values

LN2

public static final double LN2
. \begin{tabb}The values of $\ln 2$.
 \end{tabb}

See Also:
Constant Field Values

ILN2

public static final double ILN2
. \begin{tabb}The values of $1/\ln 2$.
 \end{tabb}

See Also:
Constant Field Values

MAXINTDOUBLE

public static final double MAXINTDOUBLE
. \begin{tabb}Largest integer $n_0 = 2^{53}$\ such that any integer
 $n \le n_0$\ is represented exactly as a \texttt{double}.
 \end{tabb}

See Also:
Constant Field Values

MAXTWOEXP

public static final double MAXTWOEXP
. \begin{tabb}Powers of 2 up to \texttt{MAXTWOEXP} are stored exactly
 in the array \texttt{TWOEXP}.
 \end{tabb}

See Also:
Constant Field Values

TWOEXP

public static final double[] TWOEXP
. \begin{tabb}Contains the precomputed positive powers of 2.
 One has \texttt{TWOEXP[j]}$ = 2^j$, for $j=0,\dots,64$.
 \end{tabb}


TEN_NEG_POW

public static final double[] TEN_NEG_POW
. \begin{tabb}Contains the precomputed negative powers of 10.
 One has \texttt{TEN\_NEG\_POW[j]}$ = 10^{-j}$, for $j=0,\ldots,16$.
 \end{tabb}

Method Detail

gcd

public static int gcd(int x,
                      int y)
. \begin{tabb}Returns the greatest common divisor (gcd) of $x$\ and $y$.
 \end{tabb}
xinteger yinteger the GCD of x and y


gcd

public static long gcd(long x,
                       long y)
[tabb83]
xinteger yinteger the GCD of x and y


combination

public static double combination(int n,
                                 int s)
. \begin{tabb}Returns the number of different combinations
 of $s$\ objects amongst $n$. % Uses an algorithm that prevents overflows
 \end{tabb}
ntotal number of objects snumber of chosen objects on a combination the combination of s objects amongst n


lnCombination

public static double lnCombination(int n,
                                   int s)
. \begin{tabb}Returns the natural logarithm ofnumber of different combinations
 of $s$\ objects amongst $n$.
 \end{tabb}
ntotal number of objects snumber of chosen objects on a combination the natural log of the combination


factorial

public static double factorial(int n)
. \begin{tabb}Returns the value of factorial $n$.
 \end{tabb}
nthe integer for which the factorial must be computed the value of n!


lnFactorial

public static double lnFactorial(int n)
. \begin{tabb}Returns the value of the natural logarithm of
 factorial $n$. Gives 16 decimals of precision
 (relative error $< 0.5\times 10^{-15}$).
 \end{tabb}
nargument of the log-factorial natural logarithm of n factorial


lnFactorial

public static double lnFactorial(long n)
[tabb118]
nargument of the log-factorial natural logarithm of n factorial


factoPow

public static double factoPow(int n)
. \begin{tabb}Returns the value of factorial($n$)$/n^n$.
 \end{tabb}
ninteger the value of n!/nn


calcMatStirling

public static double[][] calcMatStirling(int m,
                                         int n)
. \begin{tabb}Computes and returns the Stirling numbers of the second kind
 \end{tabb}
mnumber of rows of the allocated matrix nnumber of columns of the allocated matrix the matrix of Stirling numbers


log2

public static double log2(double x)
. \begin{tabb}Returns $\log_2 ($\texttt{x}$)$.
 \end{tabb}
xthe value for which the logarithm must be computed the value of log2(x)


lnGamma

public static double lnGamma(double x)
. \begin{tabb}Returns the natural logarithm of the gamma function $\Gamma(x)$
 eva...
 ...
 Gives 16 decimals of precision, but is implemented only for $x>0$.
 \end{tabb}
xthe value for which the lnGamma function must be computed the natural logarithm of the gamma function


lnBeta

public static double lnBeta(double lam,
                            double nu)
. \begin{tabb}Computes the natural logarithm of the Beta function
 $B(\lambda, \nu...
 ...nd{displaymath} with \texttt{lam} $=\lambda$\ and \texttt{nu} $=\nu$.
 \end{tabb}


digamma

public static double digamma(double x)
. \begin{tabb}
 Returns the value of the logarithmic derivative of the Gamma function
 $\psi(x) = \Gamma'(x) / \Gamma(x)$.
 \end{tabb}


trigamma

public static double trigamma(double x)
. \begin{tabb}
 Returns the value of the trigamma function $d\psi(x)/dx$, the derivative of
 the digamma function, evaluated at $x$.
 \end{tabb}


tetragamma

public static double tetragamma(double x)
. \begin{tabb}
 Returns the value of the tetragamma function $d^{2}\psi(x)/d^{2}x$, the second
 derivative of the digamma function, evaluated at $x$.
 \end{tabb}


gammaRatioHalf

public static double gammaRatioHalf(double x)
. \begin{tabb}
 Returns the value of the ratio $\Gamma(x+1/2)/\Gamma(x)$\ of two ga...
 ...s ratio is evaluated in a numerically stable way.
 Restriction: $x>0$.
 \end{tabb}


sumKahan

public static double sumKahan(double[] A,
                              int n)
. \begin{tabb}
 Implementation of the Kahan summation algorithm.
 Sums the first $n...
 ...hm.
 See \@ url{http://en.wikipedia.org/wiki/Kahan_summation_algorithm}.
 \end{tabb}


harmonic

public static double harmonic(long n)
. \begin{tabb}Computes the $n$-th harmonic number $H_n = \htsum_{j=1}^n 1/j$.
 \end{tabb}


harmonic2

public static double harmonic2(long n)
. \begin{tabb}Computes the sum
 \begin{displaymath}
 \sideset{}{'}\htsum_{-n/2<j\le ...
 ...m^\prime$\ means that the term with $j=0$\ is excluded
 from the sum.
 \end{tabb}


volumeSphere

public static double volumeSphere(double p,
                                  int t)
. \begin{tabb}Returns the volume $V$\ of a sphere of radius 1 in $t$\ dimensions
 ...
 ...s obtained by choosing $p=0$.
 Restrictions: $p\ge 0$\ and $t\ge 1$.
 \end{tabb}
pindex of the used norm tnumber of dimensions the volume of a sphere


bernoulliPoly

public static double bernoulliPoly(int n,
                                   double x)
. \begin{tabb}Evaluates the Bernoulli polynomial $B_n(x)$\ of degree $n$
 at $x$. ...
 ... &=& x^8-4x^7+14x^6/3 - 7x^4/3 +2x^2/3-1/30. \nonumber
 \end{eqnarray*}\end{tabb}


evalCheby

public static double evalCheby(double[] a,
                               int n,
                               double x)
. \begin{tabb}Evaluates a series of Chebyshev polynomials $T_j$\ at
 $x$\ over the...
 ...ons}
 \return{ the value of a series of Chebyshev polynomials $T_j$.}
 \end{tabb}


evalChebyStar

public static double evalChebyStar(double[] a,
                                   int n,
                                   double x)
. \begin{tabb}Evaluates a series of shifted Chebyshev polynomials $T_j^*$
 at $x$\...
 ...s}
 \return{ the value of a series of Chebyshev polynomials $T_j^*$.}
 \end{tabb}


besselK025

public static double besselK025(double x)
. \begin{tabb}Returns the value of $K_{1/4}(x)$, where $K_a$\ is the modified
 Bes...
 ...turned value is less than
 $0.5\times 10^{-6}$\ for $x > 10^{-300}$.
 \end{tabb}
xvalue at which the function is calculated the value of K1/4(x)


expBesselK1

public static double expBesselK1(double x,
                                 double y)
. \begin{tabb}
 Returns the value of $e^x K_1(y)$, where $ K_1$\ is the modified Bessel
 function of the second kind of order 1. Restriction: $y > 0$.
 \end{tabb}


erf

public static double erf(double x)
. \begin{tabb}
 Returns the value of \texttt{erf}($x$), the error function. It is d...
 ... the function is calculated}
 \return{the value of \texttt{erf}$(x)$}
 \end{tabb}


erfc

public static double erfc(double x)
. \begin{tabb}
 Returns the value of \texttt{erfc}($x$), the complementary error fu...
 ...rfc}(x) = 2/[\sqrt\pi]\htint_x^\infty dt\, e^{-t^2}.
 \end{displaymath}\end{tabb}
xvalue at which the function is calculated the value of erfc(x)


erfInv

public static double erfInv(double u)
. \begin{tabb}
 Returns the value of \texttt{erf}${}^{-1}(u)$, the inverse of the e...
 ...n. If $u =\ $\texttt{erf}$(x)$, then $x =\ $\texttt{erf}${}^{-1}(u)$.
 \end{tabb}
uvalue at which the function is calculated the value of erfInv(u)


erfcInv

public static double erfcInv(double u)
. \begin{tabb}Returns the value of \texttt{erfc}${}^{-1}(u)$, the inverse of the
 c...
 ... If $u =\ $\texttt{erfc}$(x)$,
 then $x =\ $\texttt{erfc}${}^{-1}(u)$.
 \end{tabb}
uvalue at which the function is calculated the value of erfcInv(u)


SSJ
V. labo.

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