Java Gamma gamma(double x)

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

Description

gamma

License

Apache License

Declaration

public static double gamma(double x) 

Method Source Code

//package com.java2s;
/*/*  www . ja va  2 s  .  c  om*/
 * Copyright bzewdu
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

public class Main {
    public static double gamma(double x) {
        double g = 1.0;
        double f;
        if (x > 0.0) {
            while (x < 3.0) {
                g *= x;
                ++x;
            }
            f = (1.0 - 2.0 / (7.0 * Math.pow(x, 2.0))
                    * (1.0 - 2.0 / (3.0 * Math.pow(x, 2.0))))
                    / (30.0 * Math.pow(x, 2.0));
            f = (1.0 - f) / (12.0 * x) + x * (Math.log(x) - 1.0);
            f = Math.exp(f) / g * Math.pow(6.283185307179586 / x, 0.5);
        } else {
            f = Double.POSITIVE_INFINITY;
        }
        return f;
    }
}

Related

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