Example usage for java.lang StrictMath PI

List of usage examples for java.lang StrictMath PI

Introduction

In this page you can find the example usage for java.lang StrictMath PI.

Prototype

double PI

To view the source code for java.lang StrictMath PI.

Click Source Link

Document

The double value that is closer than any other to pi, the ratio of the circumference of a circle to its diameter.

Usage

From source file:Main.java

public static void main(String[] args) {
    System.out.println("StrictMath.PI:" + StrictMath.PI);

}

From source file:org.deidentifier.arx.risk.Gamma.java

/**
 * Approximates the digamma function. Java port of the
 * "The Lightspeed Matlab toolbox" version 2.7 by Tom Minka see:
 * http://research.microsoft.com/en-us/um/people/minka/software/lightspeed/
 * /*from   w ww.j a  v  a2 s  . co m*/
 * @param x
 *            input value
 * @return approximation of digamma for x
 */
static double digamma(double x) {

    /* Illegal arguments */
    if (Double.isInfinite(x) || Double.isNaN(x)) {
        return Double.NaN;
    }

    /* Singularities */
    if (x == 0.0d) {
        return Double.NEGATIVE_INFINITY;
    }

    /* Negative values */
    /*
     * Use the reflection formula (Jeffrey 11.1.6): digamma(-x) =
     * digamma(x+1) + pi*cot(pi*x)
     * 
     * This is related to the identity digamma(-x) = digamma(x+1) -
     * digamma(z) + digamma(1-z) where z is the fractional part of x For
     * example: digamma(-3.1) = 1/3.1 + 1/2.1 + 1/1.1 + 1/0.1 +
     * digamma(1-0.1) = digamma(4.1) - digamma(0.1) + digamma(1-0.1) Then we
     * use digamma(1-z) - digamma(z) = pi*cot(pi*z)
     */
    if (x < 0.0d) {
        return digamma(1.0d - x) + (StrictMath.PI / StrictMath.tan(-StrictMath.PI * x));
    }

    /* Use Taylor series if argument <= small */
    if (x <= SMALL_DIGAMMA) {
        return (DIGAMMA_1 - (1.0d / x)) + (TRIGAMMA_1 * x);
    }

    double result = 0.0d;
    /* Reduce to digamma(X + N) where (X + N) >= large */
    while (x < LARGE_DIGAMMA) {
        result -= 1.0d / x;
        x++;
    }

    /* Use de Moivre's expansion if argument >= C */
    /* This expansion can be computed in Maple via asympt(Psi(x),x) */
    if (x >= LARGE_DIGAMMA) {
        double r = 1.0d / x;
        result += StrictMath.log(x) - (0.5d * r);
        r *= r;
        result -= r * (S3 - (r * (S4 - (r * (S5 - (r * (S6 - (r * S7))))))));
    }

    return result;
}

From source file:org.deidentifier.arx.risk.Gamma.java

/**
 * Approximates the trigamma function. Java port of the
 * "The Lightspeed Matlab toolbox" version 2.7 by Tom Minka see:
 * http://research.microsoft.com/en-us/um/people/minka/software/lightspeed/
 * /*from   w w  w  . ja va 2  s .c o m*/
 * @param x
 *            input value
 * @return approximation of trigamma for x
 */
static double trigamma(double x) {
    /* Illegal arguments */
    if (Double.isInfinite(x) || Double.isNaN(x)) {
        return Double.NaN;
    }

    /* Singularities */
    if (x == 0.0d) {
        return Double.NEGATIVE_INFINITY;
    }

    /* Negative values */
    /*
     * Use the derivative of the digamma reflection formula: -trigamma(-x) =
     * trigamma(x+1) - (pi*csc(pi*x))^2
     */
    if (x < 0.0d) {
        double r = StrictMath.PI / StrictMath.sin(-StrictMath.PI * x);
        return -trigamma(1.0d - x) + (r * r);
    }

    /* Use Taylor series if argument <= small */
    if (x <= SMALL_TRIGAMMA) {
        return (1.0d / (x * x)) + TRIGAMMA_1 + (TETRAGAMMA_1 * x);
    }

    double result = 0.0d;
    /* Reduce to trigamma(x+n) where ( X + N ) >= B */
    while (x < LARGE_TRIGAMMA) {
        result += 1.0d / (x * x);
        x++;
    }

    /* Apply asymptotic formula when X >= B */
    /* This expansion can be computed in Maple via asympt(Psi(1,x),x) */
    if (x >= LARGE_DIGAMMA) {
        double r = 1.0d / (x * x);
        result += (0.5d * r) + ((1.0d + (r * (B2 + (r * (B4 + (r * (B6 + (r * (B8 + (r * B10)))))))))) / x);
    }
    return result;
}