View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.numbers.gamma;
18  
19  /**
20   * <a href="https://mathworld.wolfram.com/GammaFunction.html">Gamma
21   * function</a> \( \Gamma(x) \).
22   *
23   * <p>The <a href="https://mathworld.wolfram.com/GammaFunction.html">gamma
24   * function</a> can be seen to extend the factorial function to cover real and
25   * complex numbers, but with its argument shifted by {@code -1}. This
26   * implementation supports real numbers.
27   *
28   * <p>This code has been adapted from:
29   * <ul>
30   *  <li>The <a href="https://www.boost.org/">Boost</a>
31   *      {@code c++} implementation {@code <boost/math/special_functions/gamma.hpp>}.
32   *  <li>The <em>NSWC Library of Mathematics Subroutines</em> double
33   *      precision implementation, {@code DGAMMA}.
34   * </ul>
35   *
36   * @see
37   * <a href="https://www.boost.org/doc/libs/1_77_0/libs/math/doc/html/math_toolkit/sf_gamma/tgamma.html">
38   * Boost C++ Gamma functions</a>
39   */
40  public final class Gamma {
41      /** Private constructor. */
42      private Gamma() {
43          // intentionally empty.
44      }
45  
46      /**
47       * Computes the value of \( \Gamma(x) \).
48       *
49       * @param x Argument.
50       * @return \( \Gamma(x) \)
51       */
52      public static double value(final double x) {
53          return BoostGamma.tgamma(x);
54      }
55  }