commons-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject svn commit: r959802 [8/10] - in /websites/production/commons/content/proper/commons-math/xref/org/apache/commons/math3: fraction/ geometry/euclidean/threed/ geometry/euclidean/twod/ ml/neuralnet/ ml/neuralnet/sofm/ ode/ ode/events/ special/ stat/infere...
Date Mon, 27 Jul 2015 19:40:45 GMT
Modified: websites/production/commons/content/proper/commons-math/xref/org/apache/commons/math3/special/Gamma.html
==============================================================================
--- websites/production/commons/content/proper/commons-math/xref/org/apache/commons/math3/special/Gamma.html (original)
+++ websites/production/commons/content/proper/commons-math/xref/org/apache/commons/math3/special/Gamma.html Mon Jul 27 19:40:45 2015
@@ -450,272 +450,280 @@
 <a class="jxr_linenumber" name="L442" href="#L442">442</a> <em class="jxr_javadoccomment">     * @since 2.0</em>
 <a class="jxr_linenumber" name="L443" href="#L443">443</a> <em class="jxr_javadoccomment">     */</em>
 <a class="jxr_linenumber" name="L444" href="#L444">444</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">static</strong> <strong class="jxr_keyword">double</strong> digamma(<strong class="jxr_keyword">double</strong> x) {
-<a class="jxr_linenumber" name="L445" href="#L445">445</a>         <strong class="jxr_keyword">if</strong> (x &gt; 0 &amp;&amp; x &lt;= S_LIMIT) {
-<a class="jxr_linenumber" name="L446" href="#L446">446</a>             <em class="jxr_comment">// use method 5 from Bernardo AS103</em>
-<a class="jxr_linenumber" name="L447" href="#L447">447</a>             <em class="jxr_comment">// accurate to O(x)</em>
-<a class="jxr_linenumber" name="L448" href="#L448">448</a>             <strong class="jxr_keyword">return</strong> -GAMMA - 1 / x;
-<a class="jxr_linenumber" name="L449" href="#L449">449</a>         }
-<a class="jxr_linenumber" name="L450" href="#L450">450</a> 
-<a class="jxr_linenumber" name="L451" href="#L451">451</a>         <strong class="jxr_keyword">if</strong> (x &gt;= C_LIMIT) {
-<a class="jxr_linenumber" name="L452" href="#L452">452</a>             <em class="jxr_comment">// use method 4 (accurate to O(1/x^8)</em>
-<a class="jxr_linenumber" name="L453" href="#L453">453</a>             <strong class="jxr_keyword">double</strong> inv = 1 / (x * x);
-<a class="jxr_linenumber" name="L454" href="#L454">454</a>             <em class="jxr_comment">//            1       1        1         1</em>
-<a class="jxr_linenumber" name="L455" href="#L455">455</a>             <em class="jxr_comment">// log(x) -  --- - ------ + ------- - -------</em>
-<a class="jxr_linenumber" name="L456" href="#L456">456</a>             <em class="jxr_comment">//           2 x   12 x^2   120 x^4   252 x^6</em>
-<a class="jxr_linenumber" name="L457" href="#L457">457</a>             <strong class="jxr_keyword">return</strong> FastMath.log(x) - 0.5 / x - inv * ((1.0 / 12) + inv * (1.0 / 120 - inv / 252));
-<a class="jxr_linenumber" name="L458" href="#L458">458</a>         }
-<a class="jxr_linenumber" name="L459" href="#L459">459</a> 
-<a class="jxr_linenumber" name="L460" href="#L460">460</a>         <strong class="jxr_keyword">return</strong> digamma(x + 1) - 1 / x;
-<a class="jxr_linenumber" name="L461" href="#L461">461</a>     }
-<a class="jxr_linenumber" name="L462" href="#L462">462</a> 
-<a class="jxr_linenumber" name="L463" href="#L463">463</a>     <em class="jxr_javadoccomment">/**</em>
-<a class="jxr_linenumber" name="L464" href="#L464">464</a> <em class="jxr_javadoccomment">     * Computes the trigamma function of x.</em>
-<a class="jxr_linenumber" name="L465" href="#L465">465</a> <em class="jxr_javadoccomment">     * This function is derived by taking the derivative of the implementation</em>
-<a class="jxr_linenumber" name="L466" href="#L466">466</a> <em class="jxr_javadoccomment">     * of digamma.</em>
-<a class="jxr_linenumber" name="L467" href="#L467">467</a> <em class="jxr_javadoccomment">     *</em>
-<a class="jxr_linenumber" name="L468" href="#L468">468</a> <em class="jxr_javadoccomment">     * @param x Argument.</em>
-<a class="jxr_linenumber" name="L469" href="#L469">469</a> <em class="jxr_javadoccomment">     * @return trigamma(x) to within 10-8 relative or absolute error whichever is smaller</em>
-<a class="jxr_linenumber" name="L470" href="#L470">470</a> <em class="jxr_javadoccomment">     * @see &lt;a href="<a href="http://en.wikipedia.org/wiki/Trigamma_function" target="alexandria_uri">http://en.wikipedia.org/wiki/Trigamma_function</a>"&gt;Trigamma&lt;/a&gt;</em>
-<a class="jxr_linenumber" name="L471" href="#L471">471</a> <em class="jxr_javadoccomment">     * @see Gamma#digamma(double)</em>
-<a class="jxr_linenumber" name="L472" href="#L472">472</a> <em class="jxr_javadoccomment">     * @since 2.0</em>
-<a class="jxr_linenumber" name="L473" href="#L473">473</a> <em class="jxr_javadoccomment">     */</em>
-<a class="jxr_linenumber" name="L474" href="#L474">474</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">static</strong> <strong class="jxr_keyword">double</strong> trigamma(<strong class="jxr_keyword">double</strong> x) {
-<a class="jxr_linenumber" name="L475" href="#L475">475</a>         <strong class="jxr_keyword">if</strong> (x &gt; 0 &amp;&amp; x &lt;= S_LIMIT) {
-<a class="jxr_linenumber" name="L476" href="#L476">476</a>             <strong class="jxr_keyword">return</strong> 1 / (x * x);
-<a class="jxr_linenumber" name="L477" href="#L477">477</a>         }
-<a class="jxr_linenumber" name="L478" href="#L478">478</a> 
-<a class="jxr_linenumber" name="L479" href="#L479">479</a>         <strong class="jxr_keyword">if</strong> (x &gt;= C_LIMIT) {
-<a class="jxr_linenumber" name="L480" href="#L480">480</a>             <strong class="jxr_keyword">double</strong> inv = 1 / (x * x);
-<a class="jxr_linenumber" name="L481" href="#L481">481</a>             <em class="jxr_comment">//  1    1      1       1       1</em>
-<a class="jxr_linenumber" name="L482" href="#L482">482</a>             <em class="jxr_comment">//  - + ---- + ---- - ----- + -----</em>
-<a class="jxr_linenumber" name="L483" href="#L483">483</a>             <em class="jxr_comment">//  x      2      3       5       7</em>
-<a class="jxr_linenumber" name="L484" href="#L484">484</a>             <em class="jxr_comment">//      2 x    6 x    30 x    42 x</em>
-<a class="jxr_linenumber" name="L485" href="#L485">485</a>             <strong class="jxr_keyword">return</strong> 1 / x + inv / 2 + inv / x * (1.0 / 6 - inv * (1.0 / 30 + inv / 42));
-<a class="jxr_linenumber" name="L486" href="#L486">486</a>         }
-<a class="jxr_linenumber" name="L487" href="#L487">487</a> 
-<a class="jxr_linenumber" name="L488" href="#L488">488</a>         <strong class="jxr_keyword">return</strong> trigamma(x + 1) + 1 / (x * x);
-<a class="jxr_linenumber" name="L489" href="#L489">489</a>     }
-<a class="jxr_linenumber" name="L490" href="#L490">490</a> 
-<a class="jxr_linenumber" name="L491" href="#L491">491</a>     <em class="jxr_javadoccomment">/**</em>
-<a class="jxr_linenumber" name="L492" href="#L492">492</a> <em class="jxr_javadoccomment">     * &lt;p&gt;</em>
-<a class="jxr_linenumber" name="L493" href="#L493">493</a> <em class="jxr_javadoccomment">     * Returns the Lanczos approximation used to compute the gamma function.</em>
-<a class="jxr_linenumber" name="L494" href="#L494">494</a> <em class="jxr_javadoccomment">     * The Lanczos approximation is related to the Gamma function by the</em>
-<a class="jxr_linenumber" name="L495" href="#L495">495</a> <em class="jxr_javadoccomment">     * following equation</em>
-<a class="jxr_linenumber" name="L496" href="#L496">496</a> <em class="jxr_javadoccomment">     * &lt;center&gt;</em>
-<a class="jxr_linenumber" name="L497" href="#L497">497</a> <em class="jxr_javadoccomment">     * {@code gamma(x) = sqrt(2 * pi) / x * (x + g + 0.5) ^ (x + 0.5)</em>
-<a class="jxr_linenumber" name="L498" href="#L498">498</a> <em class="jxr_javadoccomment">     *                   * exp(-x - g - 0.5) * lanczos(x)},</em>
-<a class="jxr_linenumber" name="L499" href="#L499">499</a> <em class="jxr_javadoccomment">     * &lt;/center&gt;</em>
-<a class="jxr_linenumber" name="L500" href="#L500">500</a> <em class="jxr_javadoccomment">     * where {@code g} is the Lanczos constant.</em>
-<a class="jxr_linenumber" name="L501" href="#L501">501</a> <em class="jxr_javadoccomment">     * &lt;/p&gt;</em>
-<a class="jxr_linenumber" name="L502" href="#L502">502</a> <em class="jxr_javadoccomment">     *</em>
-<a class="jxr_linenumber" name="L503" href="#L503">503</a> <em class="jxr_javadoccomment">     * @param x Argument.</em>
-<a class="jxr_linenumber" name="L504" href="#L504">504</a> <em class="jxr_javadoccomment">     * @return The Lanczos approximation.</em>
-<a class="jxr_linenumber" name="L505" href="#L505">505</a> <em class="jxr_javadoccomment">     * @see &lt;a href="<a href="http://mathworld.wolfram.com/LanczosApproximation.html" target="alexandria_uri">http://mathworld.wolfram.com/LanczosApproximation.html</a>"&gt;Lanczos Approximation&lt;/a&gt;</em>
-<a class="jxr_linenumber" name="L506" href="#L506">506</a> <em class="jxr_javadoccomment">     * equations (1) through (5), and Paul Godfrey's</em>
-<a class="jxr_linenumber" name="L507" href="#L507">507</a> <em class="jxr_javadoccomment">     * &lt;a href="<a href="http://my.fit.edu/~gabdo/gamma.txt" target="alexandria_uri">http://my.fit.edu/~gabdo/gamma.txt</a>"&gt;Note on the computation</em>
-<a class="jxr_linenumber" name="L508" href="#L508">508</a> <em class="jxr_javadoccomment">     * of the convergent Lanczos complex Gamma approximation&lt;/a&gt;</em>
-<a class="jxr_linenumber" name="L509" href="#L509">509</a> <em class="jxr_javadoccomment">     * @since 3.1</em>
-<a class="jxr_linenumber" name="L510" href="#L510">510</a> <em class="jxr_javadoccomment">     */</em>
-<a class="jxr_linenumber" name="L511" href="#L511">511</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">static</strong> <strong class="jxr_keyword">double</strong> lanczos(<strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">double</strong> x) {
-<a class="jxr_linenumber" name="L512" href="#L512">512</a>         <strong class="jxr_keyword">double</strong> sum = 0.0;
-<a class="jxr_linenumber" name="L513" href="#L513">513</a>         <strong class="jxr_keyword">for</strong> (<strong class="jxr_keyword">int</strong> i = LANCZOS.length - 1; i &gt; 0; --i) {
-<a class="jxr_linenumber" name="L514" href="#L514">514</a>             sum += LANCZOS[i] / (x + i);
-<a class="jxr_linenumber" name="L515" href="#L515">515</a>         }
-<a class="jxr_linenumber" name="L516" href="#L516">516</a>         <strong class="jxr_keyword">return</strong> sum + LANCZOS[0];
-<a class="jxr_linenumber" name="L517" href="#L517">517</a>     }
-<a class="jxr_linenumber" name="L518" href="#L518">518</a> 
-<a class="jxr_linenumber" name="L519" href="#L519">519</a>     <em class="jxr_javadoccomment">/**</em>
-<a class="jxr_linenumber" name="L520" href="#L520">520</a> <em class="jxr_javadoccomment">     * Returns the value of 1 / &amp;Gamma;(1 + x) - 1 for -0&amp;#46;5 &amp;le; x &amp;le;</em>
-<a class="jxr_linenumber" name="L521" href="#L521">521</a> <em class="jxr_javadoccomment">     * 1&amp;#46;5. This implementation is based on the double precision</em>
-<a class="jxr_linenumber" name="L522" href="#L522">522</a> <em class="jxr_javadoccomment">     * implementation in the &lt;em&gt;NSWC Library of Mathematics Subroutines&lt;/em&gt;,</em>
-<a class="jxr_linenumber" name="L523" href="#L523">523</a> <em class="jxr_javadoccomment">     * {@code DGAM1}.</em>
-<a class="jxr_linenumber" name="L524" href="#L524">524</a> <em class="jxr_javadoccomment">     *</em>
-<a class="jxr_linenumber" name="L525" href="#L525">525</a> <em class="jxr_javadoccomment">     * @param x Argument.</em>
-<a class="jxr_linenumber" name="L526" href="#L526">526</a> <em class="jxr_javadoccomment">     * @return The value of {@code 1.0 / Gamma(1.0 + x) - 1.0}.</em>
-<a class="jxr_linenumber" name="L527" href="#L527">527</a> <em class="jxr_javadoccomment">     * @throws NumberIsTooSmallException if {@code x &lt; -0.5}</em>
-<a class="jxr_linenumber" name="L528" href="#L528">528</a> <em class="jxr_javadoccomment">     * @throws NumberIsTooLargeException if {@code x &gt; 1.5}</em>
-<a class="jxr_linenumber" name="L529" href="#L529">529</a> <em class="jxr_javadoccomment">     * @since 3.1</em>
-<a class="jxr_linenumber" name="L530" href="#L530">530</a> <em class="jxr_javadoccomment">     */</em>
-<a class="jxr_linenumber" name="L531" href="#L531">531</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">static</strong> <strong class="jxr_keyword">double</strong> invGamma1pm1(<strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">double</strong> x) {
-<a class="jxr_linenumber" name="L532" href="#L532">532</a> 
-<a class="jxr_linenumber" name="L533" href="#L533">533</a>         <strong class="jxr_keyword">if</strong> (x &lt; -0.5) {
-<a class="jxr_linenumber" name="L534" href="#L534">534</a>             <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/commons/math3/exception/NumberIsTooSmallException.html">NumberIsTooSmallException</a>(x, -0.5, <strong class="jxr_keyword">true</strong>);
-<a class="jxr_linenumber" name="L535" href="#L535">535</a>         }
-<a class="jxr_linenumber" name="L536" href="#L536">536</a>         <strong class="jxr_keyword">if</strong> (x &gt; 1.5) {
-<a class="jxr_linenumber" name="L537" href="#L537">537</a>             <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/commons/math3/exception/NumberIsTooLargeException.html">NumberIsTooLargeException</a>(x, 1.5, <strong class="jxr_keyword">true</strong>);
-<a class="jxr_linenumber" name="L538" href="#L538">538</a>         }
-<a class="jxr_linenumber" name="L539" href="#L539">539</a> 
-<a class="jxr_linenumber" name="L540" href="#L540">540</a>         <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">double</strong> ret;
-<a class="jxr_linenumber" name="L541" href="#L541">541</a>         <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">double</strong> t = x &lt;= 0.5 ? x : (x - 0.5) - 0.5;
-<a class="jxr_linenumber" name="L542" href="#L542">542</a>         <strong class="jxr_keyword">if</strong> (t &lt; 0.0) {
-<a class="jxr_linenumber" name="L543" href="#L543">543</a>             <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">double</strong> a = INV_GAMMA1P_M1_A0 + t * INV_GAMMA1P_M1_A1;
-<a class="jxr_linenumber" name="L544" href="#L544">544</a>             <strong class="jxr_keyword">double</strong> b = INV_GAMMA1P_M1_B8;
-<a class="jxr_linenumber" name="L545" href="#L545">545</a>             b = INV_GAMMA1P_M1_B7 + t * b;
-<a class="jxr_linenumber" name="L546" href="#L546">546</a>             b = INV_GAMMA1P_M1_B6 + t * b;
-<a class="jxr_linenumber" name="L547" href="#L547">547</a>             b = INV_GAMMA1P_M1_B5 + t * b;
-<a class="jxr_linenumber" name="L548" href="#L548">548</a>             b = INV_GAMMA1P_M1_B4 + t * b;
-<a class="jxr_linenumber" name="L549" href="#L549">549</a>             b = INV_GAMMA1P_M1_B3 + t * b;
-<a class="jxr_linenumber" name="L550" href="#L550">550</a>             b = INV_GAMMA1P_M1_B2 + t * b;
-<a class="jxr_linenumber" name="L551" href="#L551">551</a>             b = INV_GAMMA1P_M1_B1 + t * b;
-<a class="jxr_linenumber" name="L552" href="#L552">552</a>             b = 1.0 + t * b;
-<a class="jxr_linenumber" name="L553" href="#L553">553</a> 
-<a class="jxr_linenumber" name="L554" href="#L554">554</a>             <strong class="jxr_keyword">double</strong> c = INV_GAMMA1P_M1_C13 + t * (a / b);
-<a class="jxr_linenumber" name="L555" href="#L555">555</a>             c = INV_GAMMA1P_M1_C12 + t * c;
-<a class="jxr_linenumber" name="L556" href="#L556">556</a>             c = INV_GAMMA1P_M1_C11 + t * c;
-<a class="jxr_linenumber" name="L557" href="#L557">557</a>             c = INV_GAMMA1P_M1_C10 + t * c;
-<a class="jxr_linenumber" name="L558" href="#L558">558</a>             c = INV_GAMMA1P_M1_C9 + t * c;
-<a class="jxr_linenumber" name="L559" href="#L559">559</a>             c = INV_GAMMA1P_M1_C8 + t * c;
-<a class="jxr_linenumber" name="L560" href="#L560">560</a>             c = INV_GAMMA1P_M1_C7 + t * c;
-<a class="jxr_linenumber" name="L561" href="#L561">561</a>             c = INV_GAMMA1P_M1_C6 + t * c;
-<a class="jxr_linenumber" name="L562" href="#L562">562</a>             c = INV_GAMMA1P_M1_C5 + t * c;
-<a class="jxr_linenumber" name="L563" href="#L563">563</a>             c = INV_GAMMA1P_M1_C4 + t * c;
-<a class="jxr_linenumber" name="L564" href="#L564">564</a>             c = INV_GAMMA1P_M1_C3 + t * c;
-<a class="jxr_linenumber" name="L565" href="#L565">565</a>             c = INV_GAMMA1P_M1_C2 + t * c;
-<a class="jxr_linenumber" name="L566" href="#L566">566</a>             c = INV_GAMMA1P_M1_C1 + t * c;
-<a class="jxr_linenumber" name="L567" href="#L567">567</a>             c = INV_GAMMA1P_M1_C + t * c;
-<a class="jxr_linenumber" name="L568" href="#L568">568</a>             <strong class="jxr_keyword">if</strong> (x &gt; 0.5) {
-<a class="jxr_linenumber" name="L569" href="#L569">569</a>                 ret = t * c / x;
-<a class="jxr_linenumber" name="L570" href="#L570">570</a>             } <strong class="jxr_keyword">else</strong> {
-<a class="jxr_linenumber" name="L571" href="#L571">571</a>                 ret = x * ((c + 0.5) + 0.5);
-<a class="jxr_linenumber" name="L572" href="#L572">572</a>             }
-<a class="jxr_linenumber" name="L573" href="#L573">573</a>         } <strong class="jxr_keyword">else</strong> {
-<a class="jxr_linenumber" name="L574" href="#L574">574</a>             <strong class="jxr_keyword">double</strong> p = INV_GAMMA1P_M1_P6;
-<a class="jxr_linenumber" name="L575" href="#L575">575</a>             p = INV_GAMMA1P_M1_P5 + t * p;
-<a class="jxr_linenumber" name="L576" href="#L576">576</a>             p = INV_GAMMA1P_M1_P4 + t * p;
-<a class="jxr_linenumber" name="L577" href="#L577">577</a>             p = INV_GAMMA1P_M1_P3 + t * p;
-<a class="jxr_linenumber" name="L578" href="#L578">578</a>             p = INV_GAMMA1P_M1_P2 + t * p;
-<a class="jxr_linenumber" name="L579" href="#L579">579</a>             p = INV_GAMMA1P_M1_P1 + t * p;
-<a class="jxr_linenumber" name="L580" href="#L580">580</a>             p = INV_GAMMA1P_M1_P0 + t * p;
-<a class="jxr_linenumber" name="L581" href="#L581">581</a> 
-<a class="jxr_linenumber" name="L582" href="#L582">582</a>             <strong class="jxr_keyword">double</strong> q = INV_GAMMA1P_M1_Q4;
-<a class="jxr_linenumber" name="L583" href="#L583">583</a>             q = INV_GAMMA1P_M1_Q3 + t * q;
-<a class="jxr_linenumber" name="L584" href="#L584">584</a>             q = INV_GAMMA1P_M1_Q2 + t * q;
-<a class="jxr_linenumber" name="L585" href="#L585">585</a>             q = INV_GAMMA1P_M1_Q1 + t * q;
-<a class="jxr_linenumber" name="L586" href="#L586">586</a>             q = 1.0 + t * q;
-<a class="jxr_linenumber" name="L587" href="#L587">587</a> 
-<a class="jxr_linenumber" name="L588" href="#L588">588</a>             <strong class="jxr_keyword">double</strong> c = INV_GAMMA1P_M1_C13 + (p / q) * t;
-<a class="jxr_linenumber" name="L589" href="#L589">589</a>             c = INV_GAMMA1P_M1_C12 + t * c;
-<a class="jxr_linenumber" name="L590" href="#L590">590</a>             c = INV_GAMMA1P_M1_C11 + t * c;
-<a class="jxr_linenumber" name="L591" href="#L591">591</a>             c = INV_GAMMA1P_M1_C10 + t * c;
-<a class="jxr_linenumber" name="L592" href="#L592">592</a>             c = INV_GAMMA1P_M1_C9 + t * c;
-<a class="jxr_linenumber" name="L593" href="#L593">593</a>             c = INV_GAMMA1P_M1_C8 + t * c;
-<a class="jxr_linenumber" name="L594" href="#L594">594</a>             c = INV_GAMMA1P_M1_C7 + t * c;
-<a class="jxr_linenumber" name="L595" href="#L595">595</a>             c = INV_GAMMA1P_M1_C6 + t * c;
-<a class="jxr_linenumber" name="L596" href="#L596">596</a>             c = INV_GAMMA1P_M1_C5 + t * c;
-<a class="jxr_linenumber" name="L597" href="#L597">597</a>             c = INV_GAMMA1P_M1_C4 + t * c;
-<a class="jxr_linenumber" name="L598" href="#L598">598</a>             c = INV_GAMMA1P_M1_C3 + t * c;
-<a class="jxr_linenumber" name="L599" href="#L599">599</a>             c = INV_GAMMA1P_M1_C2 + t * c;
-<a class="jxr_linenumber" name="L600" href="#L600">600</a>             c = INV_GAMMA1P_M1_C1 + t * c;
-<a class="jxr_linenumber" name="L601" href="#L601">601</a>             c = INV_GAMMA1P_M1_C0 + t * c;
-<a class="jxr_linenumber" name="L602" href="#L602">602</a> 
-<a class="jxr_linenumber" name="L603" href="#L603">603</a>             <strong class="jxr_keyword">if</strong> (x &gt; 0.5) {
-<a class="jxr_linenumber" name="L604" href="#L604">604</a>                 ret = (t / x) * ((c - 0.5) - 0.5);
-<a class="jxr_linenumber" name="L605" href="#L605">605</a>             } <strong class="jxr_keyword">else</strong> {
-<a class="jxr_linenumber" name="L606" href="#L606">606</a>                 ret = x * c;
-<a class="jxr_linenumber" name="L607" href="#L607">607</a>             }
-<a class="jxr_linenumber" name="L608" href="#L608">608</a>         }
-<a class="jxr_linenumber" name="L609" href="#L609">609</a> 
-<a class="jxr_linenumber" name="L610" href="#L610">610</a>         <strong class="jxr_keyword">return</strong> ret;
-<a class="jxr_linenumber" name="L611" href="#L611">611</a>     }
-<a class="jxr_linenumber" name="L612" href="#L612">612</a> 
-<a class="jxr_linenumber" name="L613" href="#L613">613</a>     <em class="jxr_javadoccomment">/**</em>
-<a class="jxr_linenumber" name="L614" href="#L614">614</a> <em class="jxr_javadoccomment">     * Returns the value of log &amp;Gamma;(1 + x) for -0&amp;#46;5 &amp;le; x &amp;le; 1&amp;#46;5.</em>
-<a class="jxr_linenumber" name="L615" href="#L615">615</a> <em class="jxr_javadoccomment">     * This implementation is based on the double precision implementation in</em>
-<a class="jxr_linenumber" name="L616" href="#L616">616</a> <em class="jxr_javadoccomment">     * the &lt;em&gt;NSWC Library of Mathematics Subroutines&lt;/em&gt;, {@code DGMLN1}.</em>
-<a class="jxr_linenumber" name="L617" href="#L617">617</a> <em class="jxr_javadoccomment">     *</em>
-<a class="jxr_linenumber" name="L618" href="#L618">618</a> <em class="jxr_javadoccomment">     * @param x Argument.</em>
-<a class="jxr_linenumber" name="L619" href="#L619">619</a> <em class="jxr_javadoccomment">     * @return The value of {@code log(Gamma(1 + x))}.</em>
-<a class="jxr_linenumber" name="L620" href="#L620">620</a> <em class="jxr_javadoccomment">     * @throws NumberIsTooSmallException if {@code x &lt; -0.5}.</em>
-<a class="jxr_linenumber" name="L621" href="#L621">621</a> <em class="jxr_javadoccomment">     * @throws NumberIsTooLargeException if {@code x &gt; 1.5}.</em>
-<a class="jxr_linenumber" name="L622" href="#L622">622</a> <em class="jxr_javadoccomment">     * @since 3.1</em>
-<a class="jxr_linenumber" name="L623" href="#L623">623</a> <em class="jxr_javadoccomment">     */</em>
-<a class="jxr_linenumber" name="L624" href="#L624">624</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">static</strong> <strong class="jxr_keyword">double</strong> logGamma1p(<strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">double</strong> x)
-<a class="jxr_linenumber" name="L625" href="#L625">625</a>         <strong class="jxr_keyword">throws</strong> NumberIsTooSmallException, <a href="../../../../../org/apache/commons/math3/exception/NumberIsTooLargeException.html">NumberIsTooLargeException</a> {
-<a class="jxr_linenumber" name="L626" href="#L626">626</a> 
-<a class="jxr_linenumber" name="L627" href="#L627">627</a>         <strong class="jxr_keyword">if</strong> (x &lt; -0.5) {
-<a class="jxr_linenumber" name="L628" href="#L628">628</a>             <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/commons/math3/exception/NumberIsTooSmallException.html">NumberIsTooSmallException</a>(x, -0.5, <strong class="jxr_keyword">true</strong>);
-<a class="jxr_linenumber" name="L629" href="#L629">629</a>         }
-<a class="jxr_linenumber" name="L630" href="#L630">630</a>         <strong class="jxr_keyword">if</strong> (x &gt; 1.5) {
-<a class="jxr_linenumber" name="L631" href="#L631">631</a>             <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/commons/math3/exception/NumberIsTooLargeException.html">NumberIsTooLargeException</a>(x, 1.5, <strong class="jxr_keyword">true</strong>);
-<a class="jxr_linenumber" name="L632" href="#L632">632</a>         }
-<a class="jxr_linenumber" name="L633" href="#L633">633</a> 
-<a class="jxr_linenumber" name="L634" href="#L634">634</a>         <strong class="jxr_keyword">return</strong> -FastMath.log1p(invGamma1pm1(x));
-<a class="jxr_linenumber" name="L635" href="#L635">635</a>     }
-<a class="jxr_linenumber" name="L636" href="#L636">636</a> 
-<a class="jxr_linenumber" name="L637" href="#L637">637</a> 
-<a class="jxr_linenumber" name="L638" href="#L638">638</a>     <em class="jxr_javadoccomment">/**</em>
-<a class="jxr_linenumber" name="L639" href="#L639">639</a> <em class="jxr_javadoccomment">     * Returns the value of Γ(x). Based on the &lt;em&gt;NSWC Library of</em>
-<a class="jxr_linenumber" name="L640" href="#L640">640</a> <em class="jxr_javadoccomment">     * Mathematics Subroutines&lt;/em&gt; double precision implementation,</em>
-<a class="jxr_linenumber" name="L641" href="#L641">641</a> <em class="jxr_javadoccomment">     * {@code DGAMMA}.</em>
-<a class="jxr_linenumber" name="L642" href="#L642">642</a> <em class="jxr_javadoccomment">     *</em>
-<a class="jxr_linenumber" name="L643" href="#L643">643</a> <em class="jxr_javadoccomment">     * @param x Argument.</em>
-<a class="jxr_linenumber" name="L644" href="#L644">644</a> <em class="jxr_javadoccomment">     * @return the value of {@code Gamma(x)}.</em>
-<a class="jxr_linenumber" name="L645" href="#L645">645</a> <em class="jxr_javadoccomment">     * @since 3.1</em>
-<a class="jxr_linenumber" name="L646" href="#L646">646</a> <em class="jxr_javadoccomment">     */</em>
-<a class="jxr_linenumber" name="L647" href="#L647">647</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">static</strong> <strong class="jxr_keyword">double</strong> gamma(<strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">double</strong> x) {
-<a class="jxr_linenumber" name="L648" href="#L648">648</a> 
-<a class="jxr_linenumber" name="L649" href="#L649">649</a>         <strong class="jxr_keyword">if</strong> ((x == FastMath.rint(x)) &amp;&amp; (x &lt;= 0.0)) {
-<a class="jxr_linenumber" name="L650" href="#L650">650</a>             <strong class="jxr_keyword">return</strong> Double.NaN;
-<a class="jxr_linenumber" name="L651" href="#L651">651</a>         }
-<a class="jxr_linenumber" name="L652" href="#L652">652</a> 
-<a class="jxr_linenumber" name="L653" href="#L653">653</a>         <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">double</strong> ret;
-<a class="jxr_linenumber" name="L654" href="#L654">654</a>         <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">double</strong> absX = FastMath.abs(x);
-<a class="jxr_linenumber" name="L655" href="#L655">655</a>         <strong class="jxr_keyword">if</strong> (absX &lt;= 20.0) {
-<a class="jxr_linenumber" name="L656" href="#L656">656</a>             <strong class="jxr_keyword">if</strong> (x &gt;= 1.0) {
-<a class="jxr_linenumber" name="L657" href="#L657">657</a>                 <em class="jxr_comment">/*</em>
-<a class="jxr_linenumber" name="L658" href="#L658">658</a> <em class="jxr_comment">                 * From the recurrence relation</em>
-<a class="jxr_linenumber" name="L659" href="#L659">659</a> <em class="jxr_comment">                 * Gamma(x) = (x - 1) * ... * (x - n) * Gamma(x - n),</em>
-<a class="jxr_linenumber" name="L660" href="#L660">660</a> <em class="jxr_comment">                 * then</em>
-<a class="jxr_linenumber" name="L661" href="#L661">661</a> <em class="jxr_comment">                 * Gamma(t) = 1 / [1 + invGamma1pm1(t - 1)],</em>
-<a class="jxr_linenumber" name="L662" href="#L662">662</a> <em class="jxr_comment">                 * where t = x - n. This means that t must satisfy</em>
-<a class="jxr_linenumber" name="L663" href="#L663">663</a> <em class="jxr_comment">                 * -0.5 &lt;= t - 1 &lt;= 1.5.</em>
-<a class="jxr_linenumber" name="L664" href="#L664">664</a> <em class="jxr_comment">                 */</em>
-<a class="jxr_linenumber" name="L665" href="#L665">665</a>                 <strong class="jxr_keyword">double</strong> prod = 1.0;
-<a class="jxr_linenumber" name="L666" href="#L666">666</a>                 <strong class="jxr_keyword">double</strong> t = x;
-<a class="jxr_linenumber" name="L667" href="#L667">667</a>                 <strong class="jxr_keyword">while</strong> (t &gt; 2.5) {
-<a class="jxr_linenumber" name="L668" href="#L668">668</a>                     t -= 1.0;
-<a class="jxr_linenumber" name="L669" href="#L669">669</a>                     prod *= t;
-<a class="jxr_linenumber" name="L670" href="#L670">670</a>                 }
-<a class="jxr_linenumber" name="L671" href="#L671">671</a>                 ret = prod / (1.0 + invGamma1pm1(t - 1.0));
-<a class="jxr_linenumber" name="L672" href="#L672">672</a>             } <strong class="jxr_keyword">else</strong> {
-<a class="jxr_linenumber" name="L673" href="#L673">673</a>                 <em class="jxr_comment">/*</em>
-<a class="jxr_linenumber" name="L674" href="#L674">674</a> <em class="jxr_comment">                 * From the recurrence relation</em>
-<a class="jxr_linenumber" name="L675" href="#L675">675</a> <em class="jxr_comment">                 * Gamma(x) = Gamma(x + n + 1) / [x * (x + 1) * ... * (x + n)]</em>
-<a class="jxr_linenumber" name="L676" href="#L676">676</a> <em class="jxr_comment">                 * then</em>
-<a class="jxr_linenumber" name="L677" href="#L677">677</a> <em class="jxr_comment">                 * Gamma(x + n + 1) = 1 / [1 + invGamma1pm1(x + n)],</em>
-<a class="jxr_linenumber" name="L678" href="#L678">678</a> <em class="jxr_comment">                 * which requires -0.5 &lt;= x + n &lt;= 1.5.</em>
-<a class="jxr_linenumber" name="L679" href="#L679">679</a> <em class="jxr_comment">                 */</em>
-<a class="jxr_linenumber" name="L680" href="#L680">680</a>                 <strong class="jxr_keyword">double</strong> prod = x;
-<a class="jxr_linenumber" name="L681" href="#L681">681</a>                 <strong class="jxr_keyword">double</strong> t = x;
-<a class="jxr_linenumber" name="L682" href="#L682">682</a>                 <strong class="jxr_keyword">while</strong> (t &lt; -0.5) {
-<a class="jxr_linenumber" name="L683" href="#L683">683</a>                     t += 1.0;
-<a class="jxr_linenumber" name="L684" href="#L684">684</a>                     prod *= t;
-<a class="jxr_linenumber" name="L685" href="#L685">685</a>                 }
-<a class="jxr_linenumber" name="L686" href="#L686">686</a>                 ret = 1.0 / (prod * (1.0 + invGamma1pm1(t)));
-<a class="jxr_linenumber" name="L687" href="#L687">687</a>             }
-<a class="jxr_linenumber" name="L688" href="#L688">688</a>         } <strong class="jxr_keyword">else</strong> {
-<a class="jxr_linenumber" name="L689" href="#L689">689</a>             <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">double</strong> y = absX + LANCZOS_G + 0.5;
-<a class="jxr_linenumber" name="L690" href="#L690">690</a>             <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">double</strong> gammaAbs = SQRT_TWO_PI / x *
-<a class="jxr_linenumber" name="L691" href="#L691">691</a>                                     FastMath.pow(y, absX + 0.5) *
-<a class="jxr_linenumber" name="L692" href="#L692">692</a>                                     FastMath.exp(-y) * lanczos(absX);
-<a class="jxr_linenumber" name="L693" href="#L693">693</a>             <strong class="jxr_keyword">if</strong> (x &gt; 0.0) {
-<a class="jxr_linenumber" name="L694" href="#L694">694</a>                 ret = gammaAbs;
-<a class="jxr_linenumber" name="L695" href="#L695">695</a>             } <strong class="jxr_keyword">else</strong> {
-<a class="jxr_linenumber" name="L696" href="#L696">696</a>                 <em class="jxr_comment">/*</em>
-<a class="jxr_linenumber" name="L697" href="#L697">697</a> <em class="jxr_comment">                 * From the reflection formula</em>
-<a class="jxr_linenumber" name="L698" href="#L698">698</a> <em class="jxr_comment">                 * Gamma(x) * Gamma(1 - x) * sin(pi * x) = pi,</em>
-<a class="jxr_linenumber" name="L699" href="#L699">699</a> <em class="jxr_comment">                 * and the recurrence relation</em>
-<a class="jxr_linenumber" name="L700" href="#L700">700</a> <em class="jxr_comment">                 * Gamma(1 - x) = -x * Gamma(-x),</em>
-<a class="jxr_linenumber" name="L701" href="#L701">701</a> <em class="jxr_comment">                 * it is found</em>
-<a class="jxr_linenumber" name="L702" href="#L702">702</a> <em class="jxr_comment">                 * Gamma(x) = -pi / [x * sin(pi * x) * Gamma(-x)].</em>
-<a class="jxr_linenumber" name="L703" href="#L703">703</a> <em class="jxr_comment">                 */</em>
-<a class="jxr_linenumber" name="L704" href="#L704">704</a>                 ret = -FastMath.PI /
-<a class="jxr_linenumber" name="L705" href="#L705">705</a>                       (x * FastMath.sin(FastMath.PI * x) * gammaAbs);
-<a class="jxr_linenumber" name="L706" href="#L706">706</a>             }
-<a class="jxr_linenumber" name="L707" href="#L707">707</a>         }
-<a class="jxr_linenumber" name="L708" href="#L708">708</a>         <strong class="jxr_keyword">return</strong> ret;
-<a class="jxr_linenumber" name="L709" href="#L709">709</a>     }
-<a class="jxr_linenumber" name="L710" href="#L710">710</a> }
+<a class="jxr_linenumber" name="L445" href="#L445">445</a>         <strong class="jxr_keyword">if</strong> (Double.isNaN(x) || Double.isInfinite(x)) {
+<a class="jxr_linenumber" name="L446" href="#L446">446</a>             <strong class="jxr_keyword">return</strong> x;
+<a class="jxr_linenumber" name="L447" href="#L447">447</a>         }
+<a class="jxr_linenumber" name="L448" href="#L448">448</a> 
+<a class="jxr_linenumber" name="L449" href="#L449">449</a>         <strong class="jxr_keyword">if</strong> (x &gt; 0 &amp;&amp; x &lt;= S_LIMIT) {
+<a class="jxr_linenumber" name="L450" href="#L450">450</a>             <em class="jxr_comment">// use method 5 from Bernardo AS103</em>
+<a class="jxr_linenumber" name="L451" href="#L451">451</a>             <em class="jxr_comment">// accurate to O(x)</em>
+<a class="jxr_linenumber" name="L452" href="#L452">452</a>             <strong class="jxr_keyword">return</strong> -GAMMA - 1 / x;
+<a class="jxr_linenumber" name="L453" href="#L453">453</a>         }
+<a class="jxr_linenumber" name="L454" href="#L454">454</a> 
+<a class="jxr_linenumber" name="L455" href="#L455">455</a>         <strong class="jxr_keyword">if</strong> (x &gt;= C_LIMIT) {
+<a class="jxr_linenumber" name="L456" href="#L456">456</a>             <em class="jxr_comment">// use method 4 (accurate to O(1/x^8)</em>
+<a class="jxr_linenumber" name="L457" href="#L457">457</a>             <strong class="jxr_keyword">double</strong> inv = 1 / (x * x);
+<a class="jxr_linenumber" name="L458" href="#L458">458</a>             <em class="jxr_comment">//            1       1        1         1</em>
+<a class="jxr_linenumber" name="L459" href="#L459">459</a>             <em class="jxr_comment">// log(x) -  --- - ------ + ------- - -------</em>
+<a class="jxr_linenumber" name="L460" href="#L460">460</a>             <em class="jxr_comment">//           2 x   12 x^2   120 x^4   252 x^6</em>
+<a class="jxr_linenumber" name="L461" href="#L461">461</a>             <strong class="jxr_keyword">return</strong> FastMath.log(x) - 0.5 / x - inv * ((1.0 / 12) + inv * (1.0 / 120 - inv / 252));
+<a class="jxr_linenumber" name="L462" href="#L462">462</a>         }
+<a class="jxr_linenumber" name="L463" href="#L463">463</a> 
+<a class="jxr_linenumber" name="L464" href="#L464">464</a>         <strong class="jxr_keyword">return</strong> digamma(x + 1) - 1 / x;
+<a class="jxr_linenumber" name="L465" href="#L465">465</a>     }
+<a class="jxr_linenumber" name="L466" href="#L466">466</a> 
+<a class="jxr_linenumber" name="L467" href="#L467">467</a>     <em class="jxr_javadoccomment">/**</em>
+<a class="jxr_linenumber" name="L468" href="#L468">468</a> <em class="jxr_javadoccomment">     * Computes the trigamma function of x.</em>
+<a class="jxr_linenumber" name="L469" href="#L469">469</a> <em class="jxr_javadoccomment">     * This function is derived by taking the derivative of the implementation</em>
+<a class="jxr_linenumber" name="L470" href="#L470">470</a> <em class="jxr_javadoccomment">     * of digamma.</em>
+<a class="jxr_linenumber" name="L471" href="#L471">471</a> <em class="jxr_javadoccomment">     *</em>
+<a class="jxr_linenumber" name="L472" href="#L472">472</a> <em class="jxr_javadoccomment">     * @param x Argument.</em>
+<a class="jxr_linenumber" name="L473" href="#L473">473</a> <em class="jxr_javadoccomment">     * @return trigamma(x) to within 10-8 relative or absolute error whichever is smaller</em>
+<a class="jxr_linenumber" name="L474" href="#L474">474</a> <em class="jxr_javadoccomment">     * @see &lt;a href="<a href="http://en.wikipedia.org/wiki/Trigamma_function" target="alexandria_uri">http://en.wikipedia.org/wiki/Trigamma_function</a>"&gt;Trigamma&lt;/a&gt;</em>
+<a class="jxr_linenumber" name="L475" href="#L475">475</a> <em class="jxr_javadoccomment">     * @see Gamma#digamma(double)</em>
+<a class="jxr_linenumber" name="L476" href="#L476">476</a> <em class="jxr_javadoccomment">     * @since 2.0</em>
+<a class="jxr_linenumber" name="L477" href="#L477">477</a> <em class="jxr_javadoccomment">     */</em>
+<a class="jxr_linenumber" name="L478" href="#L478">478</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">static</strong> <strong class="jxr_keyword">double</strong> trigamma(<strong class="jxr_keyword">double</strong> x) {
+<a class="jxr_linenumber" name="L479" href="#L479">479</a>         <strong class="jxr_keyword">if</strong> (Double.isNaN(x) || Double.isInfinite(x)) {
+<a class="jxr_linenumber" name="L480" href="#L480">480</a>             <strong class="jxr_keyword">return</strong> x;
+<a class="jxr_linenumber" name="L481" href="#L481">481</a>         }
+<a class="jxr_linenumber" name="L482" href="#L482">482</a> 
+<a class="jxr_linenumber" name="L483" href="#L483">483</a>         <strong class="jxr_keyword">if</strong> (x &gt; 0 &amp;&amp; x &lt;= S_LIMIT) {
+<a class="jxr_linenumber" name="L484" href="#L484">484</a>             <strong class="jxr_keyword">return</strong> 1 / (x * x);
+<a class="jxr_linenumber" name="L485" href="#L485">485</a>         }
+<a class="jxr_linenumber" name="L486" href="#L486">486</a> 
+<a class="jxr_linenumber" name="L487" href="#L487">487</a>         <strong class="jxr_keyword">if</strong> (x &gt;= C_LIMIT) {
+<a class="jxr_linenumber" name="L488" href="#L488">488</a>             <strong class="jxr_keyword">double</strong> inv = 1 / (x * x);
+<a class="jxr_linenumber" name="L489" href="#L489">489</a>             <em class="jxr_comment">//  1    1      1       1       1</em>
+<a class="jxr_linenumber" name="L490" href="#L490">490</a>             <em class="jxr_comment">//  - + ---- + ---- - ----- + -----</em>
+<a class="jxr_linenumber" name="L491" href="#L491">491</a>             <em class="jxr_comment">//  x      2      3       5       7</em>
+<a class="jxr_linenumber" name="L492" href="#L492">492</a>             <em class="jxr_comment">//      2 x    6 x    30 x    42 x</em>
+<a class="jxr_linenumber" name="L493" href="#L493">493</a>             <strong class="jxr_keyword">return</strong> 1 / x + inv / 2 + inv / x * (1.0 / 6 - inv * (1.0 / 30 + inv / 42));
+<a class="jxr_linenumber" name="L494" href="#L494">494</a>         }
+<a class="jxr_linenumber" name="L495" href="#L495">495</a> 
+<a class="jxr_linenumber" name="L496" href="#L496">496</a>         <strong class="jxr_keyword">return</strong> trigamma(x + 1) + 1 / (x * x);
+<a class="jxr_linenumber" name="L497" href="#L497">497</a>     }
+<a class="jxr_linenumber" name="L498" href="#L498">498</a> 
+<a class="jxr_linenumber" name="L499" href="#L499">499</a>     <em class="jxr_javadoccomment">/**</em>
+<a class="jxr_linenumber" name="L500" href="#L500">500</a> <em class="jxr_javadoccomment">     * &lt;p&gt;</em>
+<a class="jxr_linenumber" name="L501" href="#L501">501</a> <em class="jxr_javadoccomment">     * Returns the Lanczos approximation used to compute the gamma function.</em>
+<a class="jxr_linenumber" name="L502" href="#L502">502</a> <em class="jxr_javadoccomment">     * The Lanczos approximation is related to the Gamma function by the</em>
+<a class="jxr_linenumber" name="L503" href="#L503">503</a> <em class="jxr_javadoccomment">     * following equation</em>
+<a class="jxr_linenumber" name="L504" href="#L504">504</a> <em class="jxr_javadoccomment">     * &lt;center&gt;</em>
+<a class="jxr_linenumber" name="L505" href="#L505">505</a> <em class="jxr_javadoccomment">     * {@code gamma(x) = sqrt(2 * pi) / x * (x + g + 0.5) ^ (x + 0.5)</em>
+<a class="jxr_linenumber" name="L506" href="#L506">506</a> <em class="jxr_javadoccomment">     *                   * exp(-x - g - 0.5) * lanczos(x)},</em>
+<a class="jxr_linenumber" name="L507" href="#L507">507</a> <em class="jxr_javadoccomment">     * &lt;/center&gt;</em>
+<a class="jxr_linenumber" name="L508" href="#L508">508</a> <em class="jxr_javadoccomment">     * where {@code g} is the Lanczos constant.</em>
+<a class="jxr_linenumber" name="L509" href="#L509">509</a> <em class="jxr_javadoccomment">     * &lt;/p&gt;</em>
+<a class="jxr_linenumber" name="L510" href="#L510">510</a> <em class="jxr_javadoccomment">     *</em>
+<a class="jxr_linenumber" name="L511" href="#L511">511</a> <em class="jxr_javadoccomment">     * @param x Argument.</em>
+<a class="jxr_linenumber" name="L512" href="#L512">512</a> <em class="jxr_javadoccomment">     * @return The Lanczos approximation.</em>
+<a class="jxr_linenumber" name="L513" href="#L513">513</a> <em class="jxr_javadoccomment">     * @see &lt;a href="<a href="http://mathworld.wolfram.com/LanczosApproximation.html" target="alexandria_uri">http://mathworld.wolfram.com/LanczosApproximation.html</a>"&gt;Lanczos Approximation&lt;/a&gt;</em>
+<a class="jxr_linenumber" name="L514" href="#L514">514</a> <em class="jxr_javadoccomment">     * equations (1) through (5), and Paul Godfrey's</em>
+<a class="jxr_linenumber" name="L515" href="#L515">515</a> <em class="jxr_javadoccomment">     * &lt;a href="<a href="http://my.fit.edu/~gabdo/gamma.txt" target="alexandria_uri">http://my.fit.edu/~gabdo/gamma.txt</a>"&gt;Note on the computation</em>
+<a class="jxr_linenumber" name="L516" href="#L516">516</a> <em class="jxr_javadoccomment">     * of the convergent Lanczos complex Gamma approximation&lt;/a&gt;</em>
+<a class="jxr_linenumber" name="L517" href="#L517">517</a> <em class="jxr_javadoccomment">     * @since 3.1</em>
+<a class="jxr_linenumber" name="L518" href="#L518">518</a> <em class="jxr_javadoccomment">     */</em>
+<a class="jxr_linenumber" name="L519" href="#L519">519</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">static</strong> <strong class="jxr_keyword">double</strong> lanczos(<strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">double</strong> x) {
+<a class="jxr_linenumber" name="L520" href="#L520">520</a>         <strong class="jxr_keyword">double</strong> sum = 0.0;
+<a class="jxr_linenumber" name="L521" href="#L521">521</a>         <strong class="jxr_keyword">for</strong> (<strong class="jxr_keyword">int</strong> i = LANCZOS.length - 1; i &gt; 0; --i) {
+<a class="jxr_linenumber" name="L522" href="#L522">522</a>             sum += LANCZOS[i] / (x + i);
+<a class="jxr_linenumber" name="L523" href="#L523">523</a>         }
+<a class="jxr_linenumber" name="L524" href="#L524">524</a>         <strong class="jxr_keyword">return</strong> sum + LANCZOS[0];
+<a class="jxr_linenumber" name="L525" href="#L525">525</a>     }
+<a class="jxr_linenumber" name="L526" href="#L526">526</a> 
+<a class="jxr_linenumber" name="L527" href="#L527">527</a>     <em class="jxr_javadoccomment">/**</em>
+<a class="jxr_linenumber" name="L528" href="#L528">528</a> <em class="jxr_javadoccomment">     * Returns the value of 1 / &amp;Gamma;(1 + x) - 1 for -0&amp;#46;5 &amp;le; x &amp;le;</em>
+<a class="jxr_linenumber" name="L529" href="#L529">529</a> <em class="jxr_javadoccomment">     * 1&amp;#46;5. This implementation is based on the double precision</em>
+<a class="jxr_linenumber" name="L530" href="#L530">530</a> <em class="jxr_javadoccomment">     * implementation in the &lt;em&gt;NSWC Library of Mathematics Subroutines&lt;/em&gt;,</em>
+<a class="jxr_linenumber" name="L531" href="#L531">531</a> <em class="jxr_javadoccomment">     * {@code DGAM1}.</em>
+<a class="jxr_linenumber" name="L532" href="#L532">532</a> <em class="jxr_javadoccomment">     *</em>
+<a class="jxr_linenumber" name="L533" href="#L533">533</a> <em class="jxr_javadoccomment">     * @param x Argument.</em>
+<a class="jxr_linenumber" name="L534" href="#L534">534</a> <em class="jxr_javadoccomment">     * @return The value of {@code 1.0 / Gamma(1.0 + x) - 1.0}.</em>
+<a class="jxr_linenumber" name="L535" href="#L535">535</a> <em class="jxr_javadoccomment">     * @throws NumberIsTooSmallException if {@code x &lt; -0.5}</em>
+<a class="jxr_linenumber" name="L536" href="#L536">536</a> <em class="jxr_javadoccomment">     * @throws NumberIsTooLargeException if {@code x &gt; 1.5}</em>
+<a class="jxr_linenumber" name="L537" href="#L537">537</a> <em class="jxr_javadoccomment">     * @since 3.1</em>
+<a class="jxr_linenumber" name="L538" href="#L538">538</a> <em class="jxr_javadoccomment">     */</em>
+<a class="jxr_linenumber" name="L539" href="#L539">539</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">static</strong> <strong class="jxr_keyword">double</strong> invGamma1pm1(<strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">double</strong> x) {
+<a class="jxr_linenumber" name="L540" href="#L540">540</a> 
+<a class="jxr_linenumber" name="L541" href="#L541">541</a>         <strong class="jxr_keyword">if</strong> (x &lt; -0.5) {
+<a class="jxr_linenumber" name="L542" href="#L542">542</a>             <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/commons/math3/exception/NumberIsTooSmallException.html">NumberIsTooSmallException</a>(x, -0.5, <strong class="jxr_keyword">true</strong>);
+<a class="jxr_linenumber" name="L543" href="#L543">543</a>         }
+<a class="jxr_linenumber" name="L544" href="#L544">544</a>         <strong class="jxr_keyword">if</strong> (x &gt; 1.5) {
+<a class="jxr_linenumber" name="L545" href="#L545">545</a>             <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/commons/math3/exception/NumberIsTooLargeException.html">NumberIsTooLargeException</a>(x, 1.5, <strong class="jxr_keyword">true</strong>);
+<a class="jxr_linenumber" name="L546" href="#L546">546</a>         }
+<a class="jxr_linenumber" name="L547" href="#L547">547</a> 
+<a class="jxr_linenumber" name="L548" href="#L548">548</a>         <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">double</strong> ret;
+<a class="jxr_linenumber" name="L549" href="#L549">549</a>         <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">double</strong> t = x &lt;= 0.5 ? x : (x - 0.5) - 0.5;
+<a class="jxr_linenumber" name="L550" href="#L550">550</a>         <strong class="jxr_keyword">if</strong> (t &lt; 0.0) {
+<a class="jxr_linenumber" name="L551" href="#L551">551</a>             <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">double</strong> a = INV_GAMMA1P_M1_A0 + t * INV_GAMMA1P_M1_A1;
+<a class="jxr_linenumber" name="L552" href="#L552">552</a>             <strong class="jxr_keyword">double</strong> b = INV_GAMMA1P_M1_B8;
+<a class="jxr_linenumber" name="L553" href="#L553">553</a>             b = INV_GAMMA1P_M1_B7 + t * b;
+<a class="jxr_linenumber" name="L554" href="#L554">554</a>             b = INV_GAMMA1P_M1_B6 + t * b;
+<a class="jxr_linenumber" name="L555" href="#L555">555</a>             b = INV_GAMMA1P_M1_B5 + t * b;
+<a class="jxr_linenumber" name="L556" href="#L556">556</a>             b = INV_GAMMA1P_M1_B4 + t * b;
+<a class="jxr_linenumber" name="L557" href="#L557">557</a>             b = INV_GAMMA1P_M1_B3 + t * b;
+<a class="jxr_linenumber" name="L558" href="#L558">558</a>             b = INV_GAMMA1P_M1_B2 + t * b;
+<a class="jxr_linenumber" name="L559" href="#L559">559</a>             b = INV_GAMMA1P_M1_B1 + t * b;
+<a class="jxr_linenumber" name="L560" href="#L560">560</a>             b = 1.0 + t * b;
+<a class="jxr_linenumber" name="L561" href="#L561">561</a> 
+<a class="jxr_linenumber" name="L562" href="#L562">562</a>             <strong class="jxr_keyword">double</strong> c = INV_GAMMA1P_M1_C13 + t * (a / b);
+<a class="jxr_linenumber" name="L563" href="#L563">563</a>             c = INV_GAMMA1P_M1_C12 + t * c;
+<a class="jxr_linenumber" name="L564" href="#L564">564</a>             c = INV_GAMMA1P_M1_C11 + t * c;
+<a class="jxr_linenumber" name="L565" href="#L565">565</a>             c = INV_GAMMA1P_M1_C10 + t * c;
+<a class="jxr_linenumber" name="L566" href="#L566">566</a>             c = INV_GAMMA1P_M1_C9 + t * c;
+<a class="jxr_linenumber" name="L567" href="#L567">567</a>             c = INV_GAMMA1P_M1_C8 + t * c;
+<a class="jxr_linenumber" name="L568" href="#L568">568</a>             c = INV_GAMMA1P_M1_C7 + t * c;
+<a class="jxr_linenumber" name="L569" href="#L569">569</a>             c = INV_GAMMA1P_M1_C6 + t * c;
+<a class="jxr_linenumber" name="L570" href="#L570">570</a>             c = INV_GAMMA1P_M1_C5 + t * c;
+<a class="jxr_linenumber" name="L571" href="#L571">571</a>             c = INV_GAMMA1P_M1_C4 + t * c;
+<a class="jxr_linenumber" name="L572" href="#L572">572</a>             c = INV_GAMMA1P_M1_C3 + t * c;
+<a class="jxr_linenumber" name="L573" href="#L573">573</a>             c = INV_GAMMA1P_M1_C2 + t * c;
+<a class="jxr_linenumber" name="L574" href="#L574">574</a>             c = INV_GAMMA1P_M1_C1 + t * c;
+<a class="jxr_linenumber" name="L575" href="#L575">575</a>             c = INV_GAMMA1P_M1_C + t * c;
+<a class="jxr_linenumber" name="L576" href="#L576">576</a>             <strong class="jxr_keyword">if</strong> (x &gt; 0.5) {
+<a class="jxr_linenumber" name="L577" href="#L577">577</a>                 ret = t * c / x;
+<a class="jxr_linenumber" name="L578" href="#L578">578</a>             } <strong class="jxr_keyword">else</strong> {
+<a class="jxr_linenumber" name="L579" href="#L579">579</a>                 ret = x * ((c + 0.5) + 0.5);
+<a class="jxr_linenumber" name="L580" href="#L580">580</a>             }
+<a class="jxr_linenumber" name="L581" href="#L581">581</a>         } <strong class="jxr_keyword">else</strong> {
+<a class="jxr_linenumber" name="L582" href="#L582">582</a>             <strong class="jxr_keyword">double</strong> p = INV_GAMMA1P_M1_P6;
+<a class="jxr_linenumber" name="L583" href="#L583">583</a>             p = INV_GAMMA1P_M1_P5 + t * p;
+<a class="jxr_linenumber" name="L584" href="#L584">584</a>             p = INV_GAMMA1P_M1_P4 + t * p;
+<a class="jxr_linenumber" name="L585" href="#L585">585</a>             p = INV_GAMMA1P_M1_P3 + t * p;
+<a class="jxr_linenumber" name="L586" href="#L586">586</a>             p = INV_GAMMA1P_M1_P2 + t * p;
+<a class="jxr_linenumber" name="L587" href="#L587">587</a>             p = INV_GAMMA1P_M1_P1 + t * p;
+<a class="jxr_linenumber" name="L588" href="#L588">588</a>             p = INV_GAMMA1P_M1_P0 + t * p;
+<a class="jxr_linenumber" name="L589" href="#L589">589</a> 
+<a class="jxr_linenumber" name="L590" href="#L590">590</a>             <strong class="jxr_keyword">double</strong> q = INV_GAMMA1P_M1_Q4;
+<a class="jxr_linenumber" name="L591" href="#L591">591</a>             q = INV_GAMMA1P_M1_Q3 + t * q;
+<a class="jxr_linenumber" name="L592" href="#L592">592</a>             q = INV_GAMMA1P_M1_Q2 + t * q;
+<a class="jxr_linenumber" name="L593" href="#L593">593</a>             q = INV_GAMMA1P_M1_Q1 + t * q;
+<a class="jxr_linenumber" name="L594" href="#L594">594</a>             q = 1.0 + t * q;
+<a class="jxr_linenumber" name="L595" href="#L595">595</a> 
+<a class="jxr_linenumber" name="L596" href="#L596">596</a>             <strong class="jxr_keyword">double</strong> c = INV_GAMMA1P_M1_C13 + (p / q) * t;
+<a class="jxr_linenumber" name="L597" href="#L597">597</a>             c = INV_GAMMA1P_M1_C12 + t * c;
+<a class="jxr_linenumber" name="L598" href="#L598">598</a>             c = INV_GAMMA1P_M1_C11 + t * c;
+<a class="jxr_linenumber" name="L599" href="#L599">599</a>             c = INV_GAMMA1P_M1_C10 + t * c;
+<a class="jxr_linenumber" name="L600" href="#L600">600</a>             c = INV_GAMMA1P_M1_C9 + t * c;
+<a class="jxr_linenumber" name="L601" href="#L601">601</a>             c = INV_GAMMA1P_M1_C8 + t * c;
+<a class="jxr_linenumber" name="L602" href="#L602">602</a>             c = INV_GAMMA1P_M1_C7 + t * c;
+<a class="jxr_linenumber" name="L603" href="#L603">603</a>             c = INV_GAMMA1P_M1_C6 + t * c;
+<a class="jxr_linenumber" name="L604" href="#L604">604</a>             c = INV_GAMMA1P_M1_C5 + t * c;
+<a class="jxr_linenumber" name="L605" href="#L605">605</a>             c = INV_GAMMA1P_M1_C4 + t * c;
+<a class="jxr_linenumber" name="L606" href="#L606">606</a>             c = INV_GAMMA1P_M1_C3 + t * c;
+<a class="jxr_linenumber" name="L607" href="#L607">607</a>             c = INV_GAMMA1P_M1_C2 + t * c;
+<a class="jxr_linenumber" name="L608" href="#L608">608</a>             c = INV_GAMMA1P_M1_C1 + t * c;
+<a class="jxr_linenumber" name="L609" href="#L609">609</a>             c = INV_GAMMA1P_M1_C0 + t * c;
+<a class="jxr_linenumber" name="L610" href="#L610">610</a> 
+<a class="jxr_linenumber" name="L611" href="#L611">611</a>             <strong class="jxr_keyword">if</strong> (x &gt; 0.5) {
+<a class="jxr_linenumber" name="L612" href="#L612">612</a>                 ret = (t / x) * ((c - 0.5) - 0.5);
+<a class="jxr_linenumber" name="L613" href="#L613">613</a>             } <strong class="jxr_keyword">else</strong> {
+<a class="jxr_linenumber" name="L614" href="#L614">614</a>                 ret = x * c;
+<a class="jxr_linenumber" name="L615" href="#L615">615</a>             }
+<a class="jxr_linenumber" name="L616" href="#L616">616</a>         }
+<a class="jxr_linenumber" name="L617" href="#L617">617</a> 
+<a class="jxr_linenumber" name="L618" href="#L618">618</a>         <strong class="jxr_keyword">return</strong> ret;
+<a class="jxr_linenumber" name="L619" href="#L619">619</a>     }
+<a class="jxr_linenumber" name="L620" href="#L620">620</a> 
+<a class="jxr_linenumber" name="L621" href="#L621">621</a>     <em class="jxr_javadoccomment">/**</em>
+<a class="jxr_linenumber" name="L622" href="#L622">622</a> <em class="jxr_javadoccomment">     * Returns the value of log &amp;Gamma;(1 + x) for -0&amp;#46;5 &amp;le; x &amp;le; 1&amp;#46;5.</em>
+<a class="jxr_linenumber" name="L623" href="#L623">623</a> <em class="jxr_javadoccomment">     * This implementation is based on the double precision implementation in</em>
+<a class="jxr_linenumber" name="L624" href="#L624">624</a> <em class="jxr_javadoccomment">     * the &lt;em&gt;NSWC Library of Mathematics Subroutines&lt;/em&gt;, {@code DGMLN1}.</em>
+<a class="jxr_linenumber" name="L625" href="#L625">625</a> <em class="jxr_javadoccomment">     *</em>
+<a class="jxr_linenumber" name="L626" href="#L626">626</a> <em class="jxr_javadoccomment">     * @param x Argument.</em>
+<a class="jxr_linenumber" name="L627" href="#L627">627</a> <em class="jxr_javadoccomment">     * @return The value of {@code log(Gamma(1 + x))}.</em>
+<a class="jxr_linenumber" name="L628" href="#L628">628</a> <em class="jxr_javadoccomment">     * @throws NumberIsTooSmallException if {@code x &lt; -0.5}.</em>
+<a class="jxr_linenumber" name="L629" href="#L629">629</a> <em class="jxr_javadoccomment">     * @throws NumberIsTooLargeException if {@code x &gt; 1.5}.</em>
+<a class="jxr_linenumber" name="L630" href="#L630">630</a> <em class="jxr_javadoccomment">     * @since 3.1</em>
+<a class="jxr_linenumber" name="L631" href="#L631">631</a> <em class="jxr_javadoccomment">     */</em>
+<a class="jxr_linenumber" name="L632" href="#L632">632</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">static</strong> <strong class="jxr_keyword">double</strong> logGamma1p(<strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">double</strong> x)
+<a class="jxr_linenumber" name="L633" href="#L633">633</a>         <strong class="jxr_keyword">throws</strong> NumberIsTooSmallException, <a href="../../../../../org/apache/commons/math3/exception/NumberIsTooLargeException.html">NumberIsTooLargeException</a> {
+<a class="jxr_linenumber" name="L634" href="#L634">634</a> 
+<a class="jxr_linenumber" name="L635" href="#L635">635</a>         <strong class="jxr_keyword">if</strong> (x &lt; -0.5) {
+<a class="jxr_linenumber" name="L636" href="#L636">636</a>             <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/commons/math3/exception/NumberIsTooSmallException.html">NumberIsTooSmallException</a>(x, -0.5, <strong class="jxr_keyword">true</strong>);
+<a class="jxr_linenumber" name="L637" href="#L637">637</a>         }
+<a class="jxr_linenumber" name="L638" href="#L638">638</a>         <strong class="jxr_keyword">if</strong> (x &gt; 1.5) {
+<a class="jxr_linenumber" name="L639" href="#L639">639</a>             <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/commons/math3/exception/NumberIsTooLargeException.html">NumberIsTooLargeException</a>(x, 1.5, <strong class="jxr_keyword">true</strong>);
+<a class="jxr_linenumber" name="L640" href="#L640">640</a>         }
+<a class="jxr_linenumber" name="L641" href="#L641">641</a> 
+<a class="jxr_linenumber" name="L642" href="#L642">642</a>         <strong class="jxr_keyword">return</strong> -FastMath.log1p(invGamma1pm1(x));
+<a class="jxr_linenumber" name="L643" href="#L643">643</a>     }
+<a class="jxr_linenumber" name="L644" href="#L644">644</a> 
+<a class="jxr_linenumber" name="L645" href="#L645">645</a> 
+<a class="jxr_linenumber" name="L646" href="#L646">646</a>     <em class="jxr_javadoccomment">/**</em>
+<a class="jxr_linenumber" name="L647" href="#L647">647</a> <em class="jxr_javadoccomment">     * Returns the value of Γ(x). Based on the &lt;em&gt;NSWC Library of</em>
+<a class="jxr_linenumber" name="L648" href="#L648">648</a> <em class="jxr_javadoccomment">     * Mathematics Subroutines&lt;/em&gt; double precision implementation,</em>
+<a class="jxr_linenumber" name="L649" href="#L649">649</a> <em class="jxr_javadoccomment">     * {@code DGAMMA}.</em>
+<a class="jxr_linenumber" name="L650" href="#L650">650</a> <em class="jxr_javadoccomment">     *</em>
+<a class="jxr_linenumber" name="L651" href="#L651">651</a> <em class="jxr_javadoccomment">     * @param x Argument.</em>
+<a class="jxr_linenumber" name="L652" href="#L652">652</a> <em class="jxr_javadoccomment">     * @return the value of {@code Gamma(x)}.</em>
+<a class="jxr_linenumber" name="L653" href="#L653">653</a> <em class="jxr_javadoccomment">     * @since 3.1</em>
+<a class="jxr_linenumber" name="L654" href="#L654">654</a> <em class="jxr_javadoccomment">     */</em>
+<a class="jxr_linenumber" name="L655" href="#L655">655</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">static</strong> <strong class="jxr_keyword">double</strong> gamma(<strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">double</strong> x) {
+<a class="jxr_linenumber" name="L656" href="#L656">656</a> 
+<a class="jxr_linenumber" name="L657" href="#L657">657</a>         <strong class="jxr_keyword">if</strong> ((x == FastMath.rint(x)) &amp;&amp; (x &lt;= 0.0)) {
+<a class="jxr_linenumber" name="L658" href="#L658">658</a>             <strong class="jxr_keyword">return</strong> Double.NaN;
+<a class="jxr_linenumber" name="L659" href="#L659">659</a>         }
+<a class="jxr_linenumber" name="L660" href="#L660">660</a> 
+<a class="jxr_linenumber" name="L661" href="#L661">661</a>         <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">double</strong> ret;
+<a class="jxr_linenumber" name="L662" href="#L662">662</a>         <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">double</strong> absX = FastMath.abs(x);
+<a class="jxr_linenumber" name="L663" href="#L663">663</a>         <strong class="jxr_keyword">if</strong> (absX &lt;= 20.0) {
+<a class="jxr_linenumber" name="L664" href="#L664">664</a>             <strong class="jxr_keyword">if</strong> (x &gt;= 1.0) {
+<a class="jxr_linenumber" name="L665" href="#L665">665</a>                 <em class="jxr_comment">/*</em>
+<a class="jxr_linenumber" name="L666" href="#L666">666</a> <em class="jxr_comment">                 * From the recurrence relation</em>
+<a class="jxr_linenumber" name="L667" href="#L667">667</a> <em class="jxr_comment">                 * Gamma(x) = (x - 1) * ... * (x - n) * Gamma(x - n),</em>
+<a class="jxr_linenumber" name="L668" href="#L668">668</a> <em class="jxr_comment">                 * then</em>
+<a class="jxr_linenumber" name="L669" href="#L669">669</a> <em class="jxr_comment">                 * Gamma(t) = 1 / [1 + invGamma1pm1(t - 1)],</em>
+<a class="jxr_linenumber" name="L670" href="#L670">670</a> <em class="jxr_comment">                 * where t = x - n. This means that t must satisfy</em>
+<a class="jxr_linenumber" name="L671" href="#L671">671</a> <em class="jxr_comment">                 * -0.5 &lt;= t - 1 &lt;= 1.5.</em>
+<a class="jxr_linenumber" name="L672" href="#L672">672</a> <em class="jxr_comment">                 */</em>
+<a class="jxr_linenumber" name="L673" href="#L673">673</a>                 <strong class="jxr_keyword">double</strong> prod = 1.0;
+<a class="jxr_linenumber" name="L674" href="#L674">674</a>                 <strong class="jxr_keyword">double</strong> t = x;
+<a class="jxr_linenumber" name="L675" href="#L675">675</a>                 <strong class="jxr_keyword">while</strong> (t &gt; 2.5) {
+<a class="jxr_linenumber" name="L676" href="#L676">676</a>                     t -= 1.0;
+<a class="jxr_linenumber" name="L677" href="#L677">677</a>                     prod *= t;
+<a class="jxr_linenumber" name="L678" href="#L678">678</a>                 }
+<a class="jxr_linenumber" name="L679" href="#L679">679</a>                 ret = prod / (1.0 + invGamma1pm1(t - 1.0));
+<a class="jxr_linenumber" name="L680" href="#L680">680</a>             } <strong class="jxr_keyword">else</strong> {
+<a class="jxr_linenumber" name="L681" href="#L681">681</a>                 <em class="jxr_comment">/*</em>
+<a class="jxr_linenumber" name="L682" href="#L682">682</a> <em class="jxr_comment">                 * From the recurrence relation</em>
+<a class="jxr_linenumber" name="L683" href="#L683">683</a> <em class="jxr_comment">                 * Gamma(x) = Gamma(x + n + 1) / [x * (x + 1) * ... * (x + n)]</em>
+<a class="jxr_linenumber" name="L684" href="#L684">684</a> <em class="jxr_comment">                 * then</em>
+<a class="jxr_linenumber" name="L685" href="#L685">685</a> <em class="jxr_comment">                 * Gamma(x + n + 1) = 1 / [1 + invGamma1pm1(x + n)],</em>
+<a class="jxr_linenumber" name="L686" href="#L686">686</a> <em class="jxr_comment">                 * which requires -0.5 &lt;= x + n &lt;= 1.5.</em>
+<a class="jxr_linenumber" name="L687" href="#L687">687</a> <em class="jxr_comment">                 */</em>
+<a class="jxr_linenumber" name="L688" href="#L688">688</a>                 <strong class="jxr_keyword">double</strong> prod = x;
+<a class="jxr_linenumber" name="L689" href="#L689">689</a>                 <strong class="jxr_keyword">double</strong> t = x;
+<a class="jxr_linenumber" name="L690" href="#L690">690</a>                 <strong class="jxr_keyword">while</strong> (t &lt; -0.5) {
+<a class="jxr_linenumber" name="L691" href="#L691">691</a>                     t += 1.0;
+<a class="jxr_linenumber" name="L692" href="#L692">692</a>                     prod *= t;
+<a class="jxr_linenumber" name="L693" href="#L693">693</a>                 }
+<a class="jxr_linenumber" name="L694" href="#L694">694</a>                 ret = 1.0 / (prod * (1.0 + invGamma1pm1(t)));
+<a class="jxr_linenumber" name="L695" href="#L695">695</a>             }
+<a class="jxr_linenumber" name="L696" href="#L696">696</a>         } <strong class="jxr_keyword">else</strong> {
+<a class="jxr_linenumber" name="L697" href="#L697">697</a>             <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">double</strong> y = absX + LANCZOS_G + 0.5;
+<a class="jxr_linenumber" name="L698" href="#L698">698</a>             <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">double</strong> gammaAbs = SQRT_TWO_PI / x *
+<a class="jxr_linenumber" name="L699" href="#L699">699</a>                                     FastMath.pow(y, absX + 0.5) *
+<a class="jxr_linenumber" name="L700" href="#L700">700</a>                                     FastMath.exp(-y) * lanczos(absX);
+<a class="jxr_linenumber" name="L701" href="#L701">701</a>             <strong class="jxr_keyword">if</strong> (x &gt; 0.0) {
+<a class="jxr_linenumber" name="L702" href="#L702">702</a>                 ret = gammaAbs;
+<a class="jxr_linenumber" name="L703" href="#L703">703</a>             } <strong class="jxr_keyword">else</strong> {
+<a class="jxr_linenumber" name="L704" href="#L704">704</a>                 <em class="jxr_comment">/*</em>
+<a class="jxr_linenumber" name="L705" href="#L705">705</a> <em class="jxr_comment">                 * From the reflection formula</em>
+<a class="jxr_linenumber" name="L706" href="#L706">706</a> <em class="jxr_comment">                 * Gamma(x) * Gamma(1 - x) * sin(pi * x) = pi,</em>
+<a class="jxr_linenumber" name="L707" href="#L707">707</a> <em class="jxr_comment">                 * and the recurrence relation</em>
+<a class="jxr_linenumber" name="L708" href="#L708">708</a> <em class="jxr_comment">                 * Gamma(1 - x) = -x * Gamma(-x),</em>
+<a class="jxr_linenumber" name="L709" href="#L709">709</a> <em class="jxr_comment">                 * it is found</em>
+<a class="jxr_linenumber" name="L710" href="#L710">710</a> <em class="jxr_comment">                 * Gamma(x) = -pi / [x * sin(pi * x) * Gamma(-x)].</em>
+<a class="jxr_linenumber" name="L711" href="#L711">711</a> <em class="jxr_comment">                 */</em>
+<a class="jxr_linenumber" name="L712" href="#L712">712</a>                 ret = -FastMath.PI /
+<a class="jxr_linenumber" name="L713" href="#L713">713</a>                       (x * FastMath.sin(FastMath.PI * x) * gammaAbs);
+<a class="jxr_linenumber" name="L714" href="#L714">714</a>             }
+<a class="jxr_linenumber" name="L715" href="#L715">715</a>         }
+<a class="jxr_linenumber" name="L716" href="#L716">716</a>         <strong class="jxr_keyword">return</strong> ret;
+<a class="jxr_linenumber" name="L717" href="#L717">717</a>     }
+<a class="jxr_linenumber" name="L718" href="#L718">718</a> }
 </pre>
 <hr/>
 <div id="footer">Copyright &#169; 2003&#x2013;2015 <a href="http://www.apache.org/">The Apache Software Foundation</a>. All rights reserved.</div>



Mime
View raw message