Java Gamma gamma(double x)

Here you can find the source of gamma(double x)

Description

This function computes the gamme function gamma(x)

License

Open Source License

Parameter

Parameter Description
x input argument (double)

Return

gamma function gamma(x)

Declaration

static double gamma(double x) 

Method Source Code

//package com.java2s;
/**//from   w w  w  . jav  a2 s  . com
 * Copyright notice
 *
 * This file is part of the Processing library `gwoptics'
 * http://www.gwoptics.org/processing/gwoptics_p5lib/
 *
 * Copyright (C) 2009 onwards Daniel Brown and Andreas Freise
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License version 2.1 as published
 * by the Free Software Foundation.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

public class Main {
    /**
     * This function computes the gamme function gamma(x)
     *
     * @param x input argument (double)
     * @return gamma function gamma(x)
     */
    static double gamma(double x) {
        return Math.exp(logGamma(x));
    }

    static double logGamma(double x) {
        double tmp = (x - 0.5) * Math.log(x + 4.5) - (x + 4.5);
        double ser = 1.0 + 76.18009173 / (x + 0) - 86.50532033 / (x + 1) + 24.01409822 / (x + 2)
                - 1.231739516 / (x + 3) + 0.00120858003 / (x + 4) - 0.00000536382 / (x + 5);
        return tmp + Math.log(ser * Math.sqrt(2 * Math.PI));
    }
}

Related

  1. gamma(double x)
  2. gamma(double x)
  3. gamma(double x)
  4. Gamma(double z)
  5. gamma(int alpha)