commons-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject svn commit: r959801 [8/10] - in /websites/production/commons/content/proper/commons-math/apidocs: ./ org/apache/commons/math3/exception/class-use/ org/apache/commons/math3/fraction/ org/apache/commons/math3/geometry/euclidean/oned/class-use/ org/apache...
Date Mon, 27 Jul 2015 19:40:06 GMT
Modified: websites/production/commons/content/proper/commons-math/apidocs/src-html/org/apache/commons/math3/ode/events/EventState.html
==============================================================================
--- websites/production/commons/content/proper/commons-math/apidocs/src-html/org/apache/commons/math3/ode/events/EventState.html (original)
+++ websites/production/commons/content/proper/commons-math/apidocs/src-html/org/apache/commons/math3/ode/events/EventState.html Mon Jul 27 19:40:06 2015
@@ -304,127 +304,138 @@
 <span class="sourceLineNo">296</span>                            ta = forward ? ta + convergence : ta - convergence;<a name="line.296"></a>
 <span class="sourceLineNo">297</span>                            ga = f.value(ta);<a name="line.297"></a>
 <span class="sourceLineNo">298</span>                        } while ((g0Positive ^ (ga &gt;= 0)) &amp;&amp; (forward ^ (ta &gt;= tb)));<a name="line.298"></a>
-<span class="sourceLineNo">299</span>                        --i;<a name="line.299"></a>
-<span class="sourceLineNo">300</span>                    } else if (Double.isNaN(previousEventTime) ||<a name="line.300"></a>
-<span class="sourceLineNo">301</span>                               (FastMath.abs(previousEventTime - root) &gt; convergence)) {<a name="line.301"></a>
-<span class="sourceLineNo">302</span>                        pendingEventTime = root;<a name="line.302"></a>
-<span class="sourceLineNo">303</span>                        pendingEvent = true;<a name="line.303"></a>
-<span class="sourceLineNo">304</span>                        return true;<a name="line.304"></a>
-<span class="sourceLineNo">305</span>                    } else {<a name="line.305"></a>
-<span class="sourceLineNo">306</span>                        // no sign change: there is no event for now<a name="line.306"></a>
-<span class="sourceLineNo">307</span>                        ta = tb;<a name="line.307"></a>
-<span class="sourceLineNo">308</span>                        ga = gb;<a name="line.308"></a>
-<span class="sourceLineNo">309</span>                    }<a name="line.309"></a>
-<span class="sourceLineNo">310</span><a name="line.310"></a>
-<span class="sourceLineNo">311</span>                } else {<a name="line.311"></a>
-<span class="sourceLineNo">312</span>                    // no sign change: there is no event for now<a name="line.312"></a>
-<span class="sourceLineNo">313</span>                    ta = tb;<a name="line.313"></a>
-<span class="sourceLineNo">314</span>                    ga = gb;<a name="line.314"></a>
-<span class="sourceLineNo">315</span>                }<a name="line.315"></a>
-<span class="sourceLineNo">316</span><a name="line.316"></a>
-<span class="sourceLineNo">317</span>            }<a name="line.317"></a>
-<span class="sourceLineNo">318</span><a name="line.318"></a>
-<span class="sourceLineNo">319</span>            // no event during the whole step<a name="line.319"></a>
-<span class="sourceLineNo">320</span>            pendingEvent     = false;<a name="line.320"></a>
-<span class="sourceLineNo">321</span>            pendingEventTime = Double.NaN;<a name="line.321"></a>
-<span class="sourceLineNo">322</span>            return false;<a name="line.322"></a>
-<span class="sourceLineNo">323</span><a name="line.323"></a>
-<span class="sourceLineNo">324</span>        } catch (LocalMaxCountExceededException lmcee) {<a name="line.324"></a>
-<span class="sourceLineNo">325</span>            throw lmcee.getException();<a name="line.325"></a>
-<span class="sourceLineNo">326</span>        }<a name="line.326"></a>
+<span class="sourceLineNo">299</span><a name="line.299"></a>
+<span class="sourceLineNo">300</span>                        if (forward ^ (ta &gt;= tb)) {<a name="line.300"></a>
+<span class="sourceLineNo">301</span>                            // we were able to skip this spurious root<a name="line.301"></a>
+<span class="sourceLineNo">302</span>                            --i;<a name="line.302"></a>
+<span class="sourceLineNo">303</span>                        } else {<a name="line.303"></a>
+<span class="sourceLineNo">304</span>                            // we can't avoid this root before the end of the step,<a name="line.304"></a>
+<span class="sourceLineNo">305</span>                            // we have to handle it despite it is close to the former one<a name="line.305"></a>
+<span class="sourceLineNo">306</span>                            // maybe we have two very close roots<a name="line.306"></a>
+<span class="sourceLineNo">307</span>                            pendingEventTime = root;<a name="line.307"></a>
+<span class="sourceLineNo">308</span>                            pendingEvent = true;<a name="line.308"></a>
+<span class="sourceLineNo">309</span>                            return true;<a name="line.309"></a>
+<span class="sourceLineNo">310</span>                        }<a name="line.310"></a>
+<span class="sourceLineNo">311</span>                    } else if (Double.isNaN(previousEventTime) ||<a name="line.311"></a>
+<span class="sourceLineNo">312</span>                               (FastMath.abs(previousEventTime - root) &gt; convergence)) {<a name="line.312"></a>
+<span class="sourceLineNo">313</span>                        pendingEventTime = root;<a name="line.313"></a>
+<span class="sourceLineNo">314</span>                        pendingEvent = true;<a name="line.314"></a>
+<span class="sourceLineNo">315</span>                        return true;<a name="line.315"></a>
+<span class="sourceLineNo">316</span>                    } else {<a name="line.316"></a>
+<span class="sourceLineNo">317</span>                        // no sign change: there is no event for now<a name="line.317"></a>
+<span class="sourceLineNo">318</span>                        ta = tb;<a name="line.318"></a>
+<span class="sourceLineNo">319</span>                        ga = gb;<a name="line.319"></a>
+<span class="sourceLineNo">320</span>                    }<a name="line.320"></a>
+<span class="sourceLineNo">321</span><a name="line.321"></a>
+<span class="sourceLineNo">322</span>                } else {<a name="line.322"></a>
+<span class="sourceLineNo">323</span>                    // no sign change: there is no event for now<a name="line.323"></a>
+<span class="sourceLineNo">324</span>                    ta = tb;<a name="line.324"></a>
+<span class="sourceLineNo">325</span>                    ga = gb;<a name="line.325"></a>
+<span class="sourceLineNo">326</span>                }<a name="line.326"></a>
 <span class="sourceLineNo">327</span><a name="line.327"></a>
-<span class="sourceLineNo">328</span>    }<a name="line.328"></a>
+<span class="sourceLineNo">328</span>            }<a name="line.328"></a>
 <span class="sourceLineNo">329</span><a name="line.329"></a>
-<span class="sourceLineNo">330</span>    /** Get the occurrence time of the event triggered in the current step.<a name="line.330"></a>
-<span class="sourceLineNo">331</span>     * @return occurrence time of the event triggered in the current<a name="line.331"></a>
-<span class="sourceLineNo">332</span>     * step or infinity if no events are triggered<a name="line.332"></a>
-<span class="sourceLineNo">333</span>     */<a name="line.333"></a>
-<span class="sourceLineNo">334</span>    public double getEventTime() {<a name="line.334"></a>
-<span class="sourceLineNo">335</span>        return pendingEvent ?<a name="line.335"></a>
-<span class="sourceLineNo">336</span>               pendingEventTime :<a name="line.336"></a>
-<span class="sourceLineNo">337</span>               (forward ? Double.POSITIVE_INFINITY : Double.NEGATIVE_INFINITY);<a name="line.337"></a>
-<span class="sourceLineNo">338</span>    }<a name="line.338"></a>
-<span class="sourceLineNo">339</span><a name="line.339"></a>
-<span class="sourceLineNo">340</span>    /** Acknowledge the fact the step has been accepted by the integrator.<a name="line.340"></a>
-<span class="sourceLineNo">341</span>     * @param t value of the independent &lt;i&gt;time&lt;/i&gt; variable at the<a name="line.341"></a>
-<span class="sourceLineNo">342</span>     * end of the step<a name="line.342"></a>
-<span class="sourceLineNo">343</span>     * @param y array containing the current value of the state vector<a name="line.343"></a>
-<span class="sourceLineNo">344</span>     * at the end of the step<a name="line.344"></a>
-<span class="sourceLineNo">345</span>     */<a name="line.345"></a>
-<span class="sourceLineNo">346</span>    public void stepAccepted(final double t, final double[] y) {<a name="line.346"></a>
-<span class="sourceLineNo">347</span><a name="line.347"></a>
-<span class="sourceLineNo">348</span>        t0 = t;<a name="line.348"></a>
-<span class="sourceLineNo">349</span>        g0 = handler.g(t, y);<a name="line.349"></a>
+<span class="sourceLineNo">330</span>            // no event during the whole step<a name="line.330"></a>
+<span class="sourceLineNo">331</span>            pendingEvent     = false;<a name="line.331"></a>
+<span class="sourceLineNo">332</span>            pendingEventTime = Double.NaN;<a name="line.332"></a>
+<span class="sourceLineNo">333</span>            return false;<a name="line.333"></a>
+<span class="sourceLineNo">334</span><a name="line.334"></a>
+<span class="sourceLineNo">335</span>        } catch (LocalMaxCountExceededException lmcee) {<a name="line.335"></a>
+<span class="sourceLineNo">336</span>            throw lmcee.getException();<a name="line.336"></a>
+<span class="sourceLineNo">337</span>        }<a name="line.337"></a>
+<span class="sourceLineNo">338</span><a name="line.338"></a>
+<span class="sourceLineNo">339</span>    }<a name="line.339"></a>
+<span class="sourceLineNo">340</span><a name="line.340"></a>
+<span class="sourceLineNo">341</span>    /** Get the occurrence time of the event triggered in the current step.<a name="line.341"></a>
+<span class="sourceLineNo">342</span>     * @return occurrence time of the event triggered in the current<a name="line.342"></a>
+<span class="sourceLineNo">343</span>     * step or infinity if no events are triggered<a name="line.343"></a>
+<span class="sourceLineNo">344</span>     */<a name="line.344"></a>
+<span class="sourceLineNo">345</span>    public double getEventTime() {<a name="line.345"></a>
+<span class="sourceLineNo">346</span>        return pendingEvent ?<a name="line.346"></a>
+<span class="sourceLineNo">347</span>               pendingEventTime :<a name="line.347"></a>
+<span class="sourceLineNo">348</span>               (forward ? Double.POSITIVE_INFINITY : Double.NEGATIVE_INFINITY);<a name="line.348"></a>
+<span class="sourceLineNo">349</span>    }<a name="line.349"></a>
 <span class="sourceLineNo">350</span><a name="line.350"></a>
-<span class="sourceLineNo">351</span>        if (pendingEvent &amp;&amp; (FastMath.abs(pendingEventTime - t) &lt;= convergence)) {<a name="line.351"></a>
-<span class="sourceLineNo">352</span>            // force the sign to its value "just after the event"<a name="line.352"></a>
-<span class="sourceLineNo">353</span>            previousEventTime = t;<a name="line.353"></a>
-<span class="sourceLineNo">354</span>            g0Positive        = increasing;<a name="line.354"></a>
-<span class="sourceLineNo">355</span>            nextAction        = handler.eventOccurred(t, y, !(increasing ^ forward));<a name="line.355"></a>
-<span class="sourceLineNo">356</span>        } else {<a name="line.356"></a>
-<span class="sourceLineNo">357</span>            g0Positive = g0 &gt;= 0;<a name="line.357"></a>
-<span class="sourceLineNo">358</span>            nextAction = EventHandler.Action.CONTINUE;<a name="line.358"></a>
-<span class="sourceLineNo">359</span>        }<a name="line.359"></a>
-<span class="sourceLineNo">360</span>    }<a name="line.360"></a>
+<span class="sourceLineNo">351</span>    /** Acknowledge the fact the step has been accepted by the integrator.<a name="line.351"></a>
+<span class="sourceLineNo">352</span>     * @param t value of the independent &lt;i&gt;time&lt;/i&gt; variable at the<a name="line.352"></a>
+<span class="sourceLineNo">353</span>     * end of the step<a name="line.353"></a>
+<span class="sourceLineNo">354</span>     * @param y array containing the current value of the state vector<a name="line.354"></a>
+<span class="sourceLineNo">355</span>     * at the end of the step<a name="line.355"></a>
+<span class="sourceLineNo">356</span>     */<a name="line.356"></a>
+<span class="sourceLineNo">357</span>    public void stepAccepted(final double t, final double[] y) {<a name="line.357"></a>
+<span class="sourceLineNo">358</span><a name="line.358"></a>
+<span class="sourceLineNo">359</span>        t0 = t;<a name="line.359"></a>
+<span class="sourceLineNo">360</span>        g0 = handler.g(t, y);<a name="line.360"></a>
 <span class="sourceLineNo">361</span><a name="line.361"></a>
-<span class="sourceLineNo">362</span>    /** Check if the integration should be stopped at the end of the<a name="line.362"></a>
-<span class="sourceLineNo">363</span>     * current step.<a name="line.363"></a>
-<span class="sourceLineNo">364</span>     * @return true if the integration should be stopped<a name="line.364"></a>
-<span class="sourceLineNo">365</span>     */<a name="line.365"></a>
-<span class="sourceLineNo">366</span>    public boolean stop() {<a name="line.366"></a>
-<span class="sourceLineNo">367</span>        return nextAction == EventHandler.Action.STOP;<a name="line.367"></a>
-<span class="sourceLineNo">368</span>    }<a name="line.368"></a>
-<span class="sourceLineNo">369</span><a name="line.369"></a>
-<span class="sourceLineNo">370</span>    /** Let the event handler reset the state if it wants.<a name="line.370"></a>
-<span class="sourceLineNo">371</span>     * @param t value of the independent &lt;i&gt;time&lt;/i&gt; variable at the<a name="line.371"></a>
-<span class="sourceLineNo">372</span>     * beginning of the next step<a name="line.372"></a>
-<span class="sourceLineNo">373</span>     * @param y array were to put the desired state vector at the beginning<a name="line.373"></a>
-<span class="sourceLineNo">374</span>     * of the next step<a name="line.374"></a>
-<span class="sourceLineNo">375</span>     * @return true if the integrator should reset the derivatives too<a name="line.375"></a>
+<span class="sourceLineNo">362</span>        if (pendingEvent &amp;&amp; (FastMath.abs(pendingEventTime - t) &lt;= convergence)) {<a name="line.362"></a>
+<span class="sourceLineNo">363</span>            // force the sign to its value "just after the event"<a name="line.363"></a>
+<span class="sourceLineNo">364</span>            previousEventTime = t;<a name="line.364"></a>
+<span class="sourceLineNo">365</span>            g0Positive        = increasing;<a name="line.365"></a>
+<span class="sourceLineNo">366</span>            nextAction        = handler.eventOccurred(t, y, !(increasing ^ forward));<a name="line.366"></a>
+<span class="sourceLineNo">367</span>        } else {<a name="line.367"></a>
+<span class="sourceLineNo">368</span>            g0Positive = g0 &gt;= 0;<a name="line.368"></a>
+<span class="sourceLineNo">369</span>            nextAction = EventHandler.Action.CONTINUE;<a name="line.369"></a>
+<span class="sourceLineNo">370</span>        }<a name="line.370"></a>
+<span class="sourceLineNo">371</span>    }<a name="line.371"></a>
+<span class="sourceLineNo">372</span><a name="line.372"></a>
+<span class="sourceLineNo">373</span>    /** Check if the integration should be stopped at the end of the<a name="line.373"></a>
+<span class="sourceLineNo">374</span>     * current step.<a name="line.374"></a>
+<span class="sourceLineNo">375</span>     * @return true if the integration should be stopped<a name="line.375"></a>
 <span class="sourceLineNo">376</span>     */<a name="line.376"></a>
-<span class="sourceLineNo">377</span>    public boolean reset(final double t, final double[] y) {<a name="line.377"></a>
-<span class="sourceLineNo">378</span><a name="line.378"></a>
-<span class="sourceLineNo">379</span>        if (!(pendingEvent &amp;&amp; (FastMath.abs(pendingEventTime - t) &lt;= convergence))) {<a name="line.379"></a>
-<span class="sourceLineNo">380</span>            return false;<a name="line.380"></a>
-<span class="sourceLineNo">381</span>        }<a name="line.381"></a>
-<span class="sourceLineNo">382</span><a name="line.382"></a>
-<span class="sourceLineNo">383</span>        if (nextAction == EventHandler.Action.RESET_STATE) {<a name="line.383"></a>
-<span class="sourceLineNo">384</span>            handler.resetState(t, y);<a name="line.384"></a>
-<span class="sourceLineNo">385</span>        }<a name="line.385"></a>
-<span class="sourceLineNo">386</span>        pendingEvent      = false;<a name="line.386"></a>
-<span class="sourceLineNo">387</span>        pendingEventTime  = Double.NaN;<a name="line.387"></a>
-<span class="sourceLineNo">388</span><a name="line.388"></a>
-<span class="sourceLineNo">389</span>        return (nextAction == EventHandler.Action.RESET_STATE) ||<a name="line.389"></a>
-<span class="sourceLineNo">390</span>               (nextAction == EventHandler.Action.RESET_DERIVATIVES);<a name="line.390"></a>
-<span class="sourceLineNo">391</span><a name="line.391"></a>
-<span class="sourceLineNo">392</span>    }<a name="line.392"></a>
+<span class="sourceLineNo">377</span>    public boolean stop() {<a name="line.377"></a>
+<span class="sourceLineNo">378</span>        return nextAction == EventHandler.Action.STOP;<a name="line.378"></a>
+<span class="sourceLineNo">379</span>    }<a name="line.379"></a>
+<span class="sourceLineNo">380</span><a name="line.380"></a>
+<span class="sourceLineNo">381</span>    /** Let the event handler reset the state if it wants.<a name="line.381"></a>
+<span class="sourceLineNo">382</span>     * @param t value of the independent &lt;i&gt;time&lt;/i&gt; variable at the<a name="line.382"></a>
+<span class="sourceLineNo">383</span>     * beginning of the next step<a name="line.383"></a>
+<span class="sourceLineNo">384</span>     * @param y array were to put the desired state vector at the beginning<a name="line.384"></a>
+<span class="sourceLineNo">385</span>     * of the next step<a name="line.385"></a>
+<span class="sourceLineNo">386</span>     * @return true if the integrator should reset the derivatives too<a name="line.386"></a>
+<span class="sourceLineNo">387</span>     */<a name="line.387"></a>
+<span class="sourceLineNo">388</span>    public boolean reset(final double t, final double[] y) {<a name="line.388"></a>
+<span class="sourceLineNo">389</span><a name="line.389"></a>
+<span class="sourceLineNo">390</span>        if (!(pendingEvent &amp;&amp; (FastMath.abs(pendingEventTime - t) &lt;= convergence))) {<a name="line.390"></a>
+<span class="sourceLineNo">391</span>            return false;<a name="line.391"></a>
+<span class="sourceLineNo">392</span>        }<a name="line.392"></a>
 <span class="sourceLineNo">393</span><a name="line.393"></a>
-<span class="sourceLineNo">394</span>    /** Local wrapper to propagate exceptions. */<a name="line.394"></a>
-<span class="sourceLineNo">395</span>    private static class LocalMaxCountExceededException extends RuntimeException {<a name="line.395"></a>
-<span class="sourceLineNo">396</span><a name="line.396"></a>
-<span class="sourceLineNo">397</span>        /** Serializable UID. */<a name="line.397"></a>
-<span class="sourceLineNo">398</span>        private static final long serialVersionUID = 20120901L;<a name="line.398"></a>
+<span class="sourceLineNo">394</span>        if (nextAction == EventHandler.Action.RESET_STATE) {<a name="line.394"></a>
+<span class="sourceLineNo">395</span>            handler.resetState(t, y);<a name="line.395"></a>
+<span class="sourceLineNo">396</span>        }<a name="line.396"></a>
+<span class="sourceLineNo">397</span>        pendingEvent      = false;<a name="line.397"></a>
+<span class="sourceLineNo">398</span>        pendingEventTime  = Double.NaN;<a name="line.398"></a>
 <span class="sourceLineNo">399</span><a name="line.399"></a>
-<span class="sourceLineNo">400</span>        /** Wrapped exception. */<a name="line.400"></a>
-<span class="sourceLineNo">401</span>        private final MaxCountExceededException wrapped;<a name="line.401"></a>
+<span class="sourceLineNo">400</span>        return (nextAction == EventHandler.Action.RESET_STATE) ||<a name="line.400"></a>
+<span class="sourceLineNo">401</span>               (nextAction == EventHandler.Action.RESET_DERIVATIVES);<a name="line.401"></a>
 <span class="sourceLineNo">402</span><a name="line.402"></a>
-<span class="sourceLineNo">403</span>        /** Simple constructor.<a name="line.403"></a>
-<span class="sourceLineNo">404</span>         * @param exception exception to wrap<a name="line.404"></a>
-<span class="sourceLineNo">405</span>         */<a name="line.405"></a>
-<span class="sourceLineNo">406</span>        public LocalMaxCountExceededException(final MaxCountExceededException exception) {<a name="line.406"></a>
-<span class="sourceLineNo">407</span>            wrapped = exception;<a name="line.407"></a>
-<span class="sourceLineNo">408</span>        }<a name="line.408"></a>
-<span class="sourceLineNo">409</span><a name="line.409"></a>
-<span class="sourceLineNo">410</span>        /** Get the wrapped exception.<a name="line.410"></a>
-<span class="sourceLineNo">411</span>         * @return wrapped exception<a name="line.411"></a>
-<span class="sourceLineNo">412</span>         */<a name="line.412"></a>
-<span class="sourceLineNo">413</span>        public MaxCountExceededException getException() {<a name="line.413"></a>
-<span class="sourceLineNo">414</span>            return wrapped;<a name="line.414"></a>
-<span class="sourceLineNo">415</span>        }<a name="line.415"></a>
-<span class="sourceLineNo">416</span><a name="line.416"></a>
-<span class="sourceLineNo">417</span>    }<a name="line.417"></a>
-<span class="sourceLineNo">418</span><a name="line.418"></a>
-<span class="sourceLineNo">419</span>}<a name="line.419"></a>
+<span class="sourceLineNo">403</span>    }<a name="line.403"></a>
+<span class="sourceLineNo">404</span><a name="line.404"></a>
+<span class="sourceLineNo">405</span>    /** Local wrapper to propagate exceptions. */<a name="line.405"></a>
+<span class="sourceLineNo">406</span>    private static class LocalMaxCountExceededException extends RuntimeException {<a name="line.406"></a>
+<span class="sourceLineNo">407</span><a name="line.407"></a>
+<span class="sourceLineNo">408</span>        /** Serializable UID. */<a name="line.408"></a>
+<span class="sourceLineNo">409</span>        private static final long serialVersionUID = 20120901L;<a name="line.409"></a>
+<span class="sourceLineNo">410</span><a name="line.410"></a>
+<span class="sourceLineNo">411</span>        /** Wrapped exception. */<a name="line.411"></a>
+<span class="sourceLineNo">412</span>        private final MaxCountExceededException wrapped;<a name="line.412"></a>
+<span class="sourceLineNo">413</span><a name="line.413"></a>
+<span class="sourceLineNo">414</span>        /** Simple constructor.<a name="line.414"></a>
+<span class="sourceLineNo">415</span>         * @param exception exception to wrap<a name="line.415"></a>
+<span class="sourceLineNo">416</span>         */<a name="line.416"></a>
+<span class="sourceLineNo">417</span>        public LocalMaxCountExceededException(final MaxCountExceededException exception) {<a name="line.417"></a>
+<span class="sourceLineNo">418</span>            wrapped = exception;<a name="line.418"></a>
+<span class="sourceLineNo">419</span>        }<a name="line.419"></a>
+<span class="sourceLineNo">420</span><a name="line.420"></a>
+<span class="sourceLineNo">421</span>        /** Get the wrapped exception.<a name="line.421"></a>
+<span class="sourceLineNo">422</span>         * @return wrapped exception<a name="line.422"></a>
+<span class="sourceLineNo">423</span>         */<a name="line.423"></a>
+<span class="sourceLineNo">424</span>        public MaxCountExceededException getException() {<a name="line.424"></a>
+<span class="sourceLineNo">425</span>            return wrapped;<a name="line.425"></a>
+<span class="sourceLineNo">426</span>        }<a name="line.426"></a>
+<span class="sourceLineNo">427</span><a name="line.427"></a>
+<span class="sourceLineNo">428</span>    }<a name="line.428"></a>
+<span class="sourceLineNo">429</span><a name="line.429"></a>
+<span class="sourceLineNo">430</span>}<a name="line.430"></a>
 
 
 

Modified: websites/production/commons/content/proper/commons-math/apidocs/src-html/org/apache/commons/math3/special/Gamma.html
==============================================================================
--- websites/production/commons/content/proper/commons-math/apidocs/src-html/org/apache/commons/math3/special/Gamma.html (original)
+++ websites/production/commons/content/proper/commons-math/apidocs/src-html/org/apache/commons/math3/special/Gamma.html Mon Jul 27 19:40:06 2015
@@ -450,272 +450,280 @@
 <span class="sourceLineNo">442</span>     * @since 2.0<a name="line.442"></a>
 <span class="sourceLineNo">443</span>     */<a name="line.443"></a>
 <span class="sourceLineNo">444</span>    public static double digamma(double x) {<a name="line.444"></a>
-<span class="sourceLineNo">445</span>        if (x &gt; 0 &amp;&amp; x &lt;= S_LIMIT) {<a name="line.445"></a>
-<span class="sourceLineNo">446</span>            // use method 5 from Bernardo AS103<a name="line.446"></a>
-<span class="sourceLineNo">447</span>            // accurate to O(x)<a name="line.447"></a>
-<span class="sourceLineNo">448</span>            return -GAMMA - 1 / x;<a name="line.448"></a>
-<span class="sourceLineNo">449</span>        }<a name="line.449"></a>
-<span class="sourceLineNo">450</span><a name="line.450"></a>
-<span class="sourceLineNo">451</span>        if (x &gt;= C_LIMIT) {<a name="line.451"></a>
-<span class="sourceLineNo">452</span>            // use method 4 (accurate to O(1/x^8)<a name="line.452"></a>
-<span class="sourceLineNo">453</span>            double inv = 1 / (x * x);<a name="line.453"></a>
-<span class="sourceLineNo">454</span>            //            1       1        1         1<a name="line.454"></a>
-<span class="sourceLineNo">455</span>            // log(x) -  --- - ------ + ------- - -------<a name="line.455"></a>
-<span class="sourceLineNo">456</span>            //           2 x   12 x^2   120 x^4   252 x^6<a name="line.456"></a>
-<span class="sourceLineNo">457</span>            return FastMath.log(x) - 0.5 / x - inv * ((1.0 / 12) + inv * (1.0 / 120 - inv / 252));<a name="line.457"></a>
-<span class="sourceLineNo">458</span>        }<a name="line.458"></a>
-<span class="sourceLineNo">459</span><a name="line.459"></a>
-<span class="sourceLineNo">460</span>        return digamma(x + 1) - 1 / x;<a name="line.460"></a>
-<span class="sourceLineNo">461</span>    }<a name="line.461"></a>
-<span class="sourceLineNo">462</span><a name="line.462"></a>
-<span class="sourceLineNo">463</span>    /**<a name="line.463"></a>
-<span class="sourceLineNo">464</span>     * Computes the trigamma function of x.<a name="line.464"></a>
-<span class="sourceLineNo">465</span>     * This function is derived by taking the derivative of the implementation<a name="line.465"></a>
-<span class="sourceLineNo">466</span>     * of digamma.<a name="line.466"></a>
-<span class="sourceLineNo">467</span>     *<a name="line.467"></a>
-<span class="sourceLineNo">468</span>     * @param x Argument.<a name="line.468"></a>
-<span class="sourceLineNo">469</span>     * @return trigamma(x) to within 10-8 relative or absolute error whichever is smaller<a name="line.469"></a>
-<span class="sourceLineNo">470</span>     * @see &lt;a href="http://en.wikipedia.org/wiki/Trigamma_function"&gt;Trigamma&lt;/a&gt;<a name="line.470"></a>
-<span class="sourceLineNo">471</span>     * @see Gamma#digamma(double)<a name="line.471"></a>
-<span class="sourceLineNo">472</span>     * @since 2.0<a name="line.472"></a>
-<span class="sourceLineNo">473</span>     */<a name="line.473"></a>
-<span class="sourceLineNo">474</span>    public static double trigamma(double x) {<a name="line.474"></a>
-<span class="sourceLineNo">475</span>        if (x &gt; 0 &amp;&amp; x &lt;= S_LIMIT) {<a name="line.475"></a>
-<span class="sourceLineNo">476</span>            return 1 / (x * x);<a name="line.476"></a>
-<span class="sourceLineNo">477</span>        }<a name="line.477"></a>
-<span class="sourceLineNo">478</span><a name="line.478"></a>
-<span class="sourceLineNo">479</span>        if (x &gt;= C_LIMIT) {<a name="line.479"></a>
-<span class="sourceLineNo">480</span>            double inv = 1 / (x * x);<a name="line.480"></a>
-<span class="sourceLineNo">481</span>            //  1    1      1       1       1<a name="line.481"></a>
-<span class="sourceLineNo">482</span>            //  - + ---- + ---- - ----- + -----<a name="line.482"></a>
-<span class="sourceLineNo">483</span>            //  x      2      3       5       7<a name="line.483"></a>
-<span class="sourceLineNo">484</span>            //      2 x    6 x    30 x    42 x<a name="line.484"></a>
-<span class="sourceLineNo">485</span>            return 1 / x + inv / 2 + inv / x * (1.0 / 6 - inv * (1.0 / 30 + inv / 42));<a name="line.485"></a>
-<span class="sourceLineNo">486</span>        }<a name="line.486"></a>
-<span class="sourceLineNo">487</span><a name="line.487"></a>
-<span class="sourceLineNo">488</span>        return trigamma(x + 1) + 1 / (x * x);<a name="line.488"></a>
-<span class="sourceLineNo">489</span>    }<a name="line.489"></a>
-<span class="sourceLineNo">490</span><a name="line.490"></a>
-<span class="sourceLineNo">491</span>    /**<a name="line.491"></a>
-<span class="sourceLineNo">492</span>     * &lt;p&gt;<a name="line.492"></a>
-<span class="sourceLineNo">493</span>     * Returns the Lanczos approximation used to compute the gamma function.<a name="line.493"></a>
-<span class="sourceLineNo">494</span>     * The Lanczos approximation is related to the Gamma function by the<a name="line.494"></a>
-<span class="sourceLineNo">495</span>     * following equation<a name="line.495"></a>
-<span class="sourceLineNo">496</span>     * &lt;center&gt;<a name="line.496"></a>
-<span class="sourceLineNo">497</span>     * {@code gamma(x) = sqrt(2 * pi) / x * (x + g + 0.5) ^ (x + 0.5)<a name="line.497"></a>
-<span class="sourceLineNo">498</span>     *                   * exp(-x - g - 0.5) * lanczos(x)},<a name="line.498"></a>
-<span class="sourceLineNo">499</span>     * &lt;/center&gt;<a name="line.499"></a>
-<span class="sourceLineNo">500</span>     * where {@code g} is the Lanczos constant.<a name="line.500"></a>
-<span class="sourceLineNo">501</span>     * &lt;/p&gt;<a name="line.501"></a>
-<span class="sourceLineNo">502</span>     *<a name="line.502"></a>
-<span class="sourceLineNo">503</span>     * @param x Argument.<a name="line.503"></a>
-<span class="sourceLineNo">504</span>     * @return The Lanczos approximation.<a name="line.504"></a>
-<span class="sourceLineNo">505</span>     * @see &lt;a href="http://mathworld.wolfram.com/LanczosApproximation.html"&gt;Lanczos Approximation&lt;/a&gt;<a name="line.505"></a>
-<span class="sourceLineNo">506</span>     * equations (1) through (5), and Paul Godfrey's<a name="line.506"></a>
-<span class="sourceLineNo">507</span>     * &lt;a href="http://my.fit.edu/~gabdo/gamma.txt"&gt;Note on the computation<a name="line.507"></a>
-<span class="sourceLineNo">508</span>     * of the convergent Lanczos complex Gamma approximation&lt;/a&gt;<a name="line.508"></a>
-<span class="sourceLineNo">509</span>     * @since 3.1<a name="line.509"></a>
-<span class="sourceLineNo">510</span>     */<a name="line.510"></a>
-<span class="sourceLineNo">511</span>    public static double lanczos(final double x) {<a name="line.511"></a>
-<span class="sourceLineNo">512</span>        double sum = 0.0;<a name="line.512"></a>
-<span class="sourceLineNo">513</span>        for (int i = LANCZOS.length - 1; i &gt; 0; --i) {<a name="line.513"></a>
-<span class="sourceLineNo">514</span>            sum += LANCZOS[i] / (x + i);<a name="line.514"></a>
-<span class="sourceLineNo">515</span>        }<a name="line.515"></a>
-<span class="sourceLineNo">516</span>        return sum + LANCZOS[0];<a name="line.516"></a>
-<span class="sourceLineNo">517</span>    }<a name="line.517"></a>
-<span class="sourceLineNo">518</span><a name="line.518"></a>
-<span class="sourceLineNo">519</span>    /**<a name="line.519"></a>
-<span class="sourceLineNo">520</span>     * Returns the value of 1 / &amp;Gamma;(1 + x) - 1 for -0&amp;#46;5 &amp;le; x &amp;le;<a name="line.520"></a>
-<span class="sourceLineNo">521</span>     * 1&amp;#46;5. This implementation is based on the double precision<a name="line.521"></a>
-<span class="sourceLineNo">522</span>     * implementation in the &lt;em&gt;NSWC Library of Mathematics Subroutines&lt;/em&gt;,<a name="line.522"></a>
-<span class="sourceLineNo">523</span>     * {@code DGAM1}.<a name="line.523"></a>
-<span class="sourceLineNo">524</span>     *<a name="line.524"></a>
-<span class="sourceLineNo">525</span>     * @param x Argument.<a name="line.525"></a>
-<span class="sourceLineNo">526</span>     * @return The value of {@code 1.0 / Gamma(1.0 + x) - 1.0}.<a name="line.526"></a>
-<span class="sourceLineNo">527</span>     * @throws NumberIsTooSmallException if {@code x &lt; -0.5}<a name="line.527"></a>
-<span class="sourceLineNo">528</span>     * @throws NumberIsTooLargeException if {@code x &gt; 1.5}<a name="line.528"></a>
-<span class="sourceLineNo">529</span>     * @since 3.1<a name="line.529"></a>
-<span class="sourceLineNo">530</span>     */<a name="line.530"></a>
-<span class="sourceLineNo">531</span>    public static double invGamma1pm1(final double x) {<a name="line.531"></a>
-<span class="sourceLineNo">532</span><a name="line.532"></a>
-<span class="sourceLineNo">533</span>        if (x &lt; -0.5) {<a name="line.533"></a>
-<span class="sourceLineNo">534</span>            throw new NumberIsTooSmallException(x, -0.5, true);<a name="line.534"></a>
-<span class="sourceLineNo">535</span>        }<a name="line.535"></a>
-<span class="sourceLineNo">536</span>        if (x &gt; 1.5) {<a name="line.536"></a>
-<span class="sourceLineNo">537</span>            throw new NumberIsTooLargeException(x, 1.5, true);<a name="line.537"></a>
-<span class="sourceLineNo">538</span>        }<a name="line.538"></a>
-<span class="sourceLineNo">539</span><a name="line.539"></a>
-<span class="sourceLineNo">540</span>        final double ret;<a name="line.540"></a>
-<span class="sourceLineNo">541</span>        final double t = x &lt;= 0.5 ? x : (x - 0.5) - 0.5;<a name="line.541"></a>
-<span class="sourceLineNo">542</span>        if (t &lt; 0.0) {<a name="line.542"></a>
-<span class="sourceLineNo">543</span>            final double a = INV_GAMMA1P_M1_A0 + t * INV_GAMMA1P_M1_A1;<a name="line.543"></a>
-<span class="sourceLineNo">544</span>            double b = INV_GAMMA1P_M1_B8;<a name="line.544"></a>
-<span class="sourceLineNo">545</span>            b = INV_GAMMA1P_M1_B7 + t * b;<a name="line.545"></a>
-<span class="sourceLineNo">546</span>            b = INV_GAMMA1P_M1_B6 + t * b;<a name="line.546"></a>
-<span class="sourceLineNo">547</span>            b = INV_GAMMA1P_M1_B5 + t * b;<a name="line.547"></a>
-<span class="sourceLineNo">548</span>            b = INV_GAMMA1P_M1_B4 + t * b;<a name="line.548"></a>
-<span class="sourceLineNo">549</span>            b = INV_GAMMA1P_M1_B3 + t * b;<a name="line.549"></a>
-<span class="sourceLineNo">550</span>            b = INV_GAMMA1P_M1_B2 + t * b;<a name="line.550"></a>
-<span class="sourceLineNo">551</span>            b = INV_GAMMA1P_M1_B1 + t * b;<a name="line.551"></a>
-<span class="sourceLineNo">552</span>            b = 1.0 + t * b;<a name="line.552"></a>
-<span class="sourceLineNo">553</span><a name="line.553"></a>
-<span class="sourceLineNo">554</span>            double c = INV_GAMMA1P_M1_C13 + t * (a / b);<a name="line.554"></a>
-<span class="sourceLineNo">555</span>            c = INV_GAMMA1P_M1_C12 + t * c;<a name="line.555"></a>
-<span class="sourceLineNo">556</span>            c = INV_GAMMA1P_M1_C11 + t * c;<a name="line.556"></a>
-<span class="sourceLineNo">557</span>            c = INV_GAMMA1P_M1_C10 + t * c;<a name="line.557"></a>
-<span class="sourceLineNo">558</span>            c = INV_GAMMA1P_M1_C9 + t * c;<a name="line.558"></a>
-<span class="sourceLineNo">559</span>            c = INV_GAMMA1P_M1_C8 + t * c;<a name="line.559"></a>
-<span class="sourceLineNo">560</span>            c = INV_GAMMA1P_M1_C7 + t * c;<a name="line.560"></a>
-<span class="sourceLineNo">561</span>            c = INV_GAMMA1P_M1_C6 + t * c;<a name="line.561"></a>
-<span class="sourceLineNo">562</span>            c = INV_GAMMA1P_M1_C5 + t * c;<a name="line.562"></a>
-<span class="sourceLineNo">563</span>            c = INV_GAMMA1P_M1_C4 + t * c;<a name="line.563"></a>
-<span class="sourceLineNo">564</span>            c = INV_GAMMA1P_M1_C3 + t * c;<a name="line.564"></a>
-<span class="sourceLineNo">565</span>            c = INV_GAMMA1P_M1_C2 + t * c;<a name="line.565"></a>
-<span class="sourceLineNo">566</span>            c = INV_GAMMA1P_M1_C1 + t * c;<a name="line.566"></a>
-<span class="sourceLineNo">567</span>            c = INV_GAMMA1P_M1_C + t * c;<a name="line.567"></a>
-<span class="sourceLineNo">568</span>            if (x &gt; 0.5) {<a name="line.568"></a>
-<span class="sourceLineNo">569</span>                ret = t * c / x;<a name="line.569"></a>
-<span class="sourceLineNo">570</span>            } else {<a name="line.570"></a>
-<span class="sourceLineNo">571</span>                ret = x * ((c + 0.5) + 0.5);<a name="line.571"></a>
-<span class="sourceLineNo">572</span>            }<a name="line.572"></a>
-<span class="sourceLineNo">573</span>        } else {<a name="line.573"></a>
-<span class="sourceLineNo">574</span>            double p = INV_GAMMA1P_M1_P6;<a name="line.574"></a>
-<span class="sourceLineNo">575</span>            p = INV_GAMMA1P_M1_P5 + t * p;<a name="line.575"></a>
-<span class="sourceLineNo">576</span>            p = INV_GAMMA1P_M1_P4 + t * p;<a name="line.576"></a>
-<span class="sourceLineNo">577</span>            p = INV_GAMMA1P_M1_P3 + t * p;<a name="line.577"></a>
-<span class="sourceLineNo">578</span>            p = INV_GAMMA1P_M1_P2 + t * p;<a name="line.578"></a>
-<span class="sourceLineNo">579</span>            p = INV_GAMMA1P_M1_P1 + t * p;<a name="line.579"></a>
-<span class="sourceLineNo">580</span>            p = INV_GAMMA1P_M1_P0 + t * p;<a name="line.580"></a>
-<span class="sourceLineNo">581</span><a name="line.581"></a>
-<span class="sourceLineNo">582</span>            double q = INV_GAMMA1P_M1_Q4;<a name="line.582"></a>
-<span class="sourceLineNo">583</span>            q = INV_GAMMA1P_M1_Q3 + t * q;<a name="line.583"></a>
-<span class="sourceLineNo">584</span>            q = INV_GAMMA1P_M1_Q2 + t * q;<a name="line.584"></a>
-<span class="sourceLineNo">585</span>            q = INV_GAMMA1P_M1_Q1 + t * q;<a name="line.585"></a>
-<span class="sourceLineNo">586</span>            q = 1.0 + t * q;<a name="line.586"></a>
-<span class="sourceLineNo">587</span><a name="line.587"></a>
-<span class="sourceLineNo">588</span>            double c = INV_GAMMA1P_M1_C13 + (p / q) * t;<a name="line.588"></a>
-<span class="sourceLineNo">589</span>            c = INV_GAMMA1P_M1_C12 + t * c;<a name="line.589"></a>
-<span class="sourceLineNo">590</span>            c = INV_GAMMA1P_M1_C11 + t * c;<a name="line.590"></a>
-<span class="sourceLineNo">591</span>            c = INV_GAMMA1P_M1_C10 + t * c;<a name="line.591"></a>
-<span class="sourceLineNo">592</span>            c = INV_GAMMA1P_M1_C9 + t * c;<a name="line.592"></a>
-<span class="sourceLineNo">593</span>            c = INV_GAMMA1P_M1_C8 + t * c;<a name="line.593"></a>
-<span class="sourceLineNo">594</span>            c = INV_GAMMA1P_M1_C7 + t * c;<a name="line.594"></a>
-<span class="sourceLineNo">595</span>            c = INV_GAMMA1P_M1_C6 + t * c;<a name="line.595"></a>
-<span class="sourceLineNo">596</span>            c = INV_GAMMA1P_M1_C5 + t * c;<a name="line.596"></a>
-<span class="sourceLineNo">597</span>            c = INV_GAMMA1P_M1_C4 + t * c;<a name="line.597"></a>
-<span class="sourceLineNo">598</span>            c = INV_GAMMA1P_M1_C3 + t * c;<a name="line.598"></a>
-<span class="sourceLineNo">599</span>            c = INV_GAMMA1P_M1_C2 + t * c;<a name="line.599"></a>
-<span class="sourceLineNo">600</span>            c = INV_GAMMA1P_M1_C1 + t * c;<a name="line.600"></a>
-<span class="sourceLineNo">601</span>            c = INV_GAMMA1P_M1_C0 + t * c;<a name="line.601"></a>
-<span class="sourceLineNo">602</span><a name="line.602"></a>
-<span class="sourceLineNo">603</span>            if (x &gt; 0.5) {<a name="line.603"></a>
-<span class="sourceLineNo">604</span>                ret = (t / x) * ((c - 0.5) - 0.5);<a name="line.604"></a>
-<span class="sourceLineNo">605</span>            } else {<a name="line.605"></a>
-<span class="sourceLineNo">606</span>                ret = x * c;<a name="line.606"></a>
-<span class="sourceLineNo">607</span>            }<a name="line.607"></a>
-<span class="sourceLineNo">608</span>        }<a name="line.608"></a>
-<span class="sourceLineNo">609</span><a name="line.609"></a>
-<span class="sourceLineNo">610</span>        return ret;<a name="line.610"></a>
-<span class="sourceLineNo">611</span>    }<a name="line.611"></a>
-<span class="sourceLineNo">612</span><a name="line.612"></a>
-<span class="sourceLineNo">613</span>    /**<a name="line.613"></a>
-<span class="sourceLineNo">614</span>     * Returns the value of log &amp;Gamma;(1 + x) for -0&amp;#46;5 &amp;le; x &amp;le; 1&amp;#46;5.<a name="line.614"></a>
-<span class="sourceLineNo">615</span>     * This implementation is based on the double precision implementation in<a name="line.615"></a>
-<span class="sourceLineNo">616</span>     * the &lt;em&gt;NSWC Library of Mathematics Subroutines&lt;/em&gt;, {@code DGMLN1}.<a name="line.616"></a>
-<span class="sourceLineNo">617</span>     *<a name="line.617"></a>
-<span class="sourceLineNo">618</span>     * @param x Argument.<a name="line.618"></a>
-<span class="sourceLineNo">619</span>     * @return The value of {@code log(Gamma(1 + x))}.<a name="line.619"></a>
-<span class="sourceLineNo">620</span>     * @throws NumberIsTooSmallException if {@code x &lt; -0.5}.<a name="line.620"></a>
-<span class="sourceLineNo">621</span>     * @throws NumberIsTooLargeException if {@code x &gt; 1.5}.<a name="line.621"></a>
-<span class="sourceLineNo">622</span>     * @since 3.1<a name="line.622"></a>
-<span class="sourceLineNo">623</span>     */<a name="line.623"></a>
-<span class="sourceLineNo">624</span>    public static double logGamma1p(final double x)<a name="line.624"></a>
-<span class="sourceLineNo">625</span>        throws NumberIsTooSmallException, NumberIsTooLargeException {<a name="line.625"></a>
-<span class="sourceLineNo">626</span><a name="line.626"></a>
-<span class="sourceLineNo">627</span>        if (x &lt; -0.5) {<a name="line.627"></a>
-<span class="sourceLineNo">628</span>            throw new NumberIsTooSmallException(x, -0.5, true);<a name="line.628"></a>
-<span class="sourceLineNo">629</span>        }<a name="line.629"></a>
-<span class="sourceLineNo">630</span>        if (x &gt; 1.5) {<a name="line.630"></a>
-<span class="sourceLineNo">631</span>            throw new NumberIsTooLargeException(x, 1.5, true);<a name="line.631"></a>
-<span class="sourceLineNo">632</span>        }<a name="line.632"></a>
-<span class="sourceLineNo">633</span><a name="line.633"></a>
-<span class="sourceLineNo">634</span>        return -FastMath.log1p(invGamma1pm1(x));<a name="line.634"></a>
-<span class="sourceLineNo">635</span>    }<a name="line.635"></a>
-<span class="sourceLineNo">636</span><a name="line.636"></a>
-<span class="sourceLineNo">637</span><a name="line.637"></a>
-<span class="sourceLineNo">638</span>    /**<a name="line.638"></a>
-<span class="sourceLineNo">639</span>     * Returns the value of ?(x). Based on the &lt;em&gt;NSWC Library of<a name="line.639"></a>
-<span class="sourceLineNo">640</span>     * Mathematics Subroutines&lt;/em&gt; double precision implementation,<a name="line.640"></a>
-<span class="sourceLineNo">641</span>     * {@code DGAMMA}.<a name="line.641"></a>
-<span class="sourceLineNo">642</span>     *<a name="line.642"></a>
-<span class="sourceLineNo">643</span>     * @param x Argument.<a name="line.643"></a>
-<span class="sourceLineNo">644</span>     * @return the value of {@code Gamma(x)}.<a name="line.644"></a>
-<span class="sourceLineNo">645</span>     * @since 3.1<a name="line.645"></a>
-<span class="sourceLineNo">646</span>     */<a name="line.646"></a>
-<span class="sourceLineNo">647</span>    public static double gamma(final double x) {<a name="line.647"></a>
-<span class="sourceLineNo">648</span><a name="line.648"></a>
-<span class="sourceLineNo">649</span>        if ((x == FastMath.rint(x)) &amp;&amp; (x &lt;= 0.0)) {<a name="line.649"></a>
-<span class="sourceLineNo">650</span>            return Double.NaN;<a name="line.650"></a>
-<span class="sourceLineNo">651</span>        }<a name="line.651"></a>
-<span class="sourceLineNo">652</span><a name="line.652"></a>
-<span class="sourceLineNo">653</span>        final double ret;<a name="line.653"></a>
-<span class="sourceLineNo">654</span>        final double absX = FastMath.abs(x);<a name="line.654"></a>
-<span class="sourceLineNo">655</span>        if (absX &lt;= 20.0) {<a name="line.655"></a>
-<span class="sourceLineNo">656</span>            if (x &gt;= 1.0) {<a name="line.656"></a>
-<span class="sourceLineNo">657</span>                /*<a name="line.657"></a>
-<span class="sourceLineNo">658</span>                 * From the recurrence relation<a name="line.658"></a>
-<span class="sourceLineNo">659</span>                 * Gamma(x) = (x - 1) * ... * (x - n) * Gamma(x - n),<a name="line.659"></a>
-<span class="sourceLineNo">660</span>                 * then<a name="line.660"></a>
-<span class="sourceLineNo">661</span>                 * Gamma(t) = 1 / [1 + invGamma1pm1(t - 1)],<a name="line.661"></a>
-<span class="sourceLineNo">662</span>                 * where t = x - n. This means that t must satisfy<a name="line.662"></a>
-<span class="sourceLineNo">663</span>                 * -0.5 &lt;= t - 1 &lt;= 1.5.<a name="line.663"></a>
-<span class="sourceLineNo">664</span>                 */<a name="line.664"></a>
-<span class="sourceLineNo">665</span>                double prod = 1.0;<a name="line.665"></a>
-<span class="sourceLineNo">666</span>                double t = x;<a name="line.666"></a>
-<span class="sourceLineNo">667</span>                while (t &gt; 2.5) {<a name="line.667"></a>
-<span class="sourceLineNo">668</span>                    t -= 1.0;<a name="line.668"></a>
-<span class="sourceLineNo">669</span>                    prod *= t;<a name="line.669"></a>
-<span class="sourceLineNo">670</span>                }<a name="line.670"></a>
-<span class="sourceLineNo">671</span>                ret = prod / (1.0 + invGamma1pm1(t - 1.0));<a name="line.671"></a>
-<span class="sourceLineNo">672</span>            } else {<a name="line.672"></a>
-<span class="sourceLineNo">673</span>                /*<a name="line.673"></a>
-<span class="sourceLineNo">674</span>                 * From the recurrence relation<a name="line.674"></a>
-<span class="sourceLineNo">675</span>                 * Gamma(x) = Gamma(x + n + 1) / [x * (x + 1) * ... * (x + n)]<a name="line.675"></a>
-<span class="sourceLineNo">676</span>                 * then<a name="line.676"></a>
-<span class="sourceLineNo">677</span>                 * Gamma(x + n + 1) = 1 / [1 + invGamma1pm1(x + n)],<a name="line.677"></a>
-<span class="sourceLineNo">678</span>                 * which requires -0.5 &lt;= x + n &lt;= 1.5.<a name="line.678"></a>
-<span class="sourceLineNo">679</span>                 */<a name="line.679"></a>
-<span class="sourceLineNo">680</span>                double prod = x;<a name="line.680"></a>
-<span class="sourceLineNo">681</span>                double t = x;<a name="line.681"></a>
-<span class="sourceLineNo">682</span>                while (t &lt; -0.5) {<a name="line.682"></a>
-<span class="sourceLineNo">683</span>                    t += 1.0;<a name="line.683"></a>
-<span class="sourceLineNo">684</span>                    prod *= t;<a name="line.684"></a>
-<span class="sourceLineNo">685</span>                }<a name="line.685"></a>
-<span class="sourceLineNo">686</span>                ret = 1.0 / (prod * (1.0 + invGamma1pm1(t)));<a name="line.686"></a>
-<span class="sourceLineNo">687</span>            }<a name="line.687"></a>
-<span class="sourceLineNo">688</span>        } else {<a name="line.688"></a>
-<span class="sourceLineNo">689</span>            final double y = absX + LANCZOS_G + 0.5;<a name="line.689"></a>
-<span class="sourceLineNo">690</span>            final double gammaAbs = SQRT_TWO_PI / x *<a name="line.690"></a>
-<span class="sourceLineNo">691</span>                                    FastMath.pow(y, absX + 0.5) *<a name="line.691"></a>
-<span class="sourceLineNo">692</span>                                    FastMath.exp(-y) * lanczos(absX);<a name="line.692"></a>
-<span class="sourceLineNo">693</span>            if (x &gt; 0.0) {<a name="line.693"></a>
-<span class="sourceLineNo">694</span>                ret = gammaAbs;<a name="line.694"></a>
-<span class="sourceLineNo">695</span>            } else {<a name="line.695"></a>
-<span class="sourceLineNo">696</span>                /*<a name="line.696"></a>
-<span class="sourceLineNo">697</span>                 * From the reflection formula<a name="line.697"></a>
-<span class="sourceLineNo">698</span>                 * Gamma(x) * Gamma(1 - x) * sin(pi * x) = pi,<a name="line.698"></a>
-<span class="sourceLineNo">699</span>                 * and the recurrence relation<a name="line.699"></a>
-<span class="sourceLineNo">700</span>                 * Gamma(1 - x) = -x * Gamma(-x),<a name="line.700"></a>
-<span class="sourceLineNo">701</span>                 * it is found<a name="line.701"></a>
-<span class="sourceLineNo">702</span>                 * Gamma(x) = -pi / [x * sin(pi * x) * Gamma(-x)].<a name="line.702"></a>
-<span class="sourceLineNo">703</span>                 */<a name="line.703"></a>
-<span class="sourceLineNo">704</span>                ret = -FastMath.PI /<a name="line.704"></a>
-<span class="sourceLineNo">705</span>                      (x * FastMath.sin(FastMath.PI * x) * gammaAbs);<a name="line.705"></a>
-<span class="sourceLineNo">706</span>            }<a name="line.706"></a>
-<span class="sourceLineNo">707</span>        }<a name="line.707"></a>
-<span class="sourceLineNo">708</span>        return ret;<a name="line.708"></a>
-<span class="sourceLineNo">709</span>    }<a name="line.709"></a>
-<span class="sourceLineNo">710</span>}<a name="line.710"></a>
+<span class="sourceLineNo">445</span>        if (Double.isNaN(x) || Double.isInfinite(x)) {<a name="line.445"></a>
+<span class="sourceLineNo">446</span>            return x;<a name="line.446"></a>
+<span class="sourceLineNo">447</span>        }<a name="line.447"></a>
+<span class="sourceLineNo">448</span><a name="line.448"></a>
+<span class="sourceLineNo">449</span>        if (x &gt; 0 &amp;&amp; x &lt;= S_LIMIT) {<a name="line.449"></a>
+<span class="sourceLineNo">450</span>            // use method 5 from Bernardo AS103<a name="line.450"></a>
+<span class="sourceLineNo">451</span>            // accurate to O(x)<a name="line.451"></a>
+<span class="sourceLineNo">452</span>            return -GAMMA - 1 / x;<a name="line.452"></a>
+<span class="sourceLineNo">453</span>        }<a name="line.453"></a>
+<span class="sourceLineNo">454</span><a name="line.454"></a>
+<span class="sourceLineNo">455</span>        if (x &gt;= C_LIMIT) {<a name="line.455"></a>
+<span class="sourceLineNo">456</span>            // use method 4 (accurate to O(1/x^8)<a name="line.456"></a>
+<span class="sourceLineNo">457</span>            double inv = 1 / (x * x);<a name="line.457"></a>
+<span class="sourceLineNo">458</span>            //            1       1        1         1<a name="line.458"></a>
+<span class="sourceLineNo">459</span>            // log(x) -  --- - ------ + ------- - -------<a name="line.459"></a>
+<span class="sourceLineNo">460</span>            //           2 x   12 x^2   120 x^4   252 x^6<a name="line.460"></a>
+<span class="sourceLineNo">461</span>            return FastMath.log(x) - 0.5 / x - inv * ((1.0 / 12) + inv * (1.0 / 120 - inv / 252));<a name="line.461"></a>
+<span class="sourceLineNo">462</span>        }<a name="line.462"></a>
+<span class="sourceLineNo">463</span><a name="line.463"></a>
+<span class="sourceLineNo">464</span>        return digamma(x + 1) - 1 / x;<a name="line.464"></a>
+<span class="sourceLineNo">465</span>    }<a name="line.465"></a>
+<span class="sourceLineNo">466</span><a name="line.466"></a>
+<span class="sourceLineNo">467</span>    /**<a name="line.467"></a>
+<span class="sourceLineNo">468</span>     * Computes the trigamma function of x.<a name="line.468"></a>
+<span class="sourceLineNo">469</span>     * This function is derived by taking the derivative of the implementation<a name="line.469"></a>
+<span class="sourceLineNo">470</span>     * of digamma.<a name="line.470"></a>
+<span class="sourceLineNo">471</span>     *<a name="line.471"></a>
+<span class="sourceLineNo">472</span>     * @param x Argument.<a name="line.472"></a>
+<span class="sourceLineNo">473</span>     * @return trigamma(x) to within 10-8 relative or absolute error whichever is smaller<a name="line.473"></a>
+<span class="sourceLineNo">474</span>     * @see &lt;a href="http://en.wikipedia.org/wiki/Trigamma_function"&gt;Trigamma&lt;/a&gt;<a name="line.474"></a>
+<span class="sourceLineNo">475</span>     * @see Gamma#digamma(double)<a name="line.475"></a>
+<span class="sourceLineNo">476</span>     * @since 2.0<a name="line.476"></a>
+<span class="sourceLineNo">477</span>     */<a name="line.477"></a>
+<span class="sourceLineNo">478</span>    public static double trigamma(double x) {<a name="line.478"></a>
+<span class="sourceLineNo">479</span>        if (Double.isNaN(x) || Double.isInfinite(x)) {<a name="line.479"></a>
+<span class="sourceLineNo">480</span>            return x;<a name="line.480"></a>
+<span class="sourceLineNo">481</span>        }<a name="line.481"></a>
+<span class="sourceLineNo">482</span><a name="line.482"></a>
+<span class="sourceLineNo">483</span>        if (x &gt; 0 &amp;&amp; x &lt;= S_LIMIT) {<a name="line.483"></a>
+<span class="sourceLineNo">484</span>            return 1 / (x * x);<a name="line.484"></a>
+<span class="sourceLineNo">485</span>        }<a name="line.485"></a>
+<span class="sourceLineNo">486</span><a name="line.486"></a>
+<span class="sourceLineNo">487</span>        if (x &gt;= C_LIMIT) {<a name="line.487"></a>
+<span class="sourceLineNo">488</span>            double inv = 1 / (x * x);<a name="line.488"></a>
+<span class="sourceLineNo">489</span>            //  1    1      1       1       1<a name="line.489"></a>
+<span class="sourceLineNo">490</span>            //  - + ---- + ---- - ----- + -----<a name="line.490"></a>
+<span class="sourceLineNo">491</span>            //  x      2      3       5       7<a name="line.491"></a>
+<span class="sourceLineNo">492</span>            //      2 x    6 x    30 x    42 x<a name="line.492"></a>
+<span class="sourceLineNo">493</span>            return 1 / x + inv / 2 + inv / x * (1.0 / 6 - inv * (1.0 / 30 + inv / 42));<a name="line.493"></a>
+<span class="sourceLineNo">494</span>        }<a name="line.494"></a>
+<span class="sourceLineNo">495</span><a name="line.495"></a>
+<span class="sourceLineNo">496</span>        return trigamma(x + 1) + 1 / (x * x);<a name="line.496"></a>
+<span class="sourceLineNo">497</span>    }<a name="line.497"></a>
+<span class="sourceLineNo">498</span><a name="line.498"></a>
+<span class="sourceLineNo">499</span>    /**<a name="line.499"></a>
+<span class="sourceLineNo">500</span>     * &lt;p&gt;<a name="line.500"></a>
+<span class="sourceLineNo">501</span>     * Returns the Lanczos approximation used to compute the gamma function.<a name="line.501"></a>
+<span class="sourceLineNo">502</span>     * The Lanczos approximation is related to the Gamma function by the<a name="line.502"></a>
+<span class="sourceLineNo">503</span>     * following equation<a name="line.503"></a>
+<span class="sourceLineNo">504</span>     * &lt;center&gt;<a name="line.504"></a>
+<span class="sourceLineNo">505</span>     * {@code gamma(x) = sqrt(2 * pi) / x * (x + g + 0.5) ^ (x + 0.5)<a name="line.505"></a>
+<span class="sourceLineNo">506</span>     *                   * exp(-x - g - 0.5) * lanczos(x)},<a name="line.506"></a>
+<span class="sourceLineNo">507</span>     * &lt;/center&gt;<a name="line.507"></a>
+<span class="sourceLineNo">508</span>     * where {@code g} is the Lanczos constant.<a name="line.508"></a>
+<span class="sourceLineNo">509</span>     * &lt;/p&gt;<a name="line.509"></a>
+<span class="sourceLineNo">510</span>     *<a name="line.510"></a>
+<span class="sourceLineNo">511</span>     * @param x Argument.<a name="line.511"></a>
+<span class="sourceLineNo">512</span>     * @return The Lanczos approximation.<a name="line.512"></a>
+<span class="sourceLineNo">513</span>     * @see &lt;a href="http://mathworld.wolfram.com/LanczosApproximation.html"&gt;Lanczos Approximation&lt;/a&gt;<a name="line.513"></a>
+<span class="sourceLineNo">514</span>     * equations (1) through (5), and Paul Godfrey's<a name="line.514"></a>
+<span class="sourceLineNo">515</span>     * &lt;a href="http://my.fit.edu/~gabdo/gamma.txt"&gt;Note on the computation<a name="line.515"></a>
+<span class="sourceLineNo">516</span>     * of the convergent Lanczos complex Gamma approximation&lt;/a&gt;<a name="line.516"></a>
+<span class="sourceLineNo">517</span>     * @since 3.1<a name="line.517"></a>
+<span class="sourceLineNo">518</span>     */<a name="line.518"></a>
+<span class="sourceLineNo">519</span>    public static double lanczos(final double x) {<a name="line.519"></a>
+<span class="sourceLineNo">520</span>        double sum = 0.0;<a name="line.520"></a>
+<span class="sourceLineNo">521</span>        for (int i = LANCZOS.length - 1; i &gt; 0; --i) {<a name="line.521"></a>
+<span class="sourceLineNo">522</span>            sum += LANCZOS[i] / (x + i);<a name="line.522"></a>
+<span class="sourceLineNo">523</span>        }<a name="line.523"></a>
+<span class="sourceLineNo">524</span>        return sum + LANCZOS[0];<a name="line.524"></a>
+<span class="sourceLineNo">525</span>    }<a name="line.525"></a>
+<span class="sourceLineNo">526</span><a name="line.526"></a>
+<span class="sourceLineNo">527</span>    /**<a name="line.527"></a>
+<span class="sourceLineNo">528</span>     * Returns the value of 1 / &amp;Gamma;(1 + x) - 1 for -0&amp;#46;5 &amp;le; x &amp;le;<a name="line.528"></a>
+<span class="sourceLineNo">529</span>     * 1&amp;#46;5. This implementation is based on the double precision<a name="line.529"></a>
+<span class="sourceLineNo">530</span>     * implementation in the &lt;em&gt;NSWC Library of Mathematics Subroutines&lt;/em&gt;,<a name="line.530"></a>
+<span class="sourceLineNo">531</span>     * {@code DGAM1}.<a name="line.531"></a>
+<span class="sourceLineNo">532</span>     *<a name="line.532"></a>
+<span class="sourceLineNo">533</span>     * @param x Argument.<a name="line.533"></a>
+<span class="sourceLineNo">534</span>     * @return The value of {@code 1.0 / Gamma(1.0 + x) - 1.0}.<a name="line.534"></a>
+<span class="sourceLineNo">535</span>     * @throws NumberIsTooSmallException if {@code x &lt; -0.5}<a name="line.535"></a>
+<span class="sourceLineNo">536</span>     * @throws NumberIsTooLargeException if {@code x &gt; 1.5}<a name="line.536"></a>
+<span class="sourceLineNo">537</span>     * @since 3.1<a name="line.537"></a>
+<span class="sourceLineNo">538</span>     */<a name="line.538"></a>
+<span class="sourceLineNo">539</span>    public static double invGamma1pm1(final double x) {<a name="line.539"></a>
+<span class="sourceLineNo">540</span><a name="line.540"></a>
+<span class="sourceLineNo">541</span>        if (x &lt; -0.5) {<a name="line.541"></a>
+<span class="sourceLineNo">542</span>            throw new NumberIsTooSmallException(x, -0.5, true);<a name="line.542"></a>
+<span class="sourceLineNo">543</span>        }<a name="line.543"></a>
+<span class="sourceLineNo">544</span>        if (x &gt; 1.5) {<a name="line.544"></a>
+<span class="sourceLineNo">545</span>            throw new NumberIsTooLargeException(x, 1.5, true);<a name="line.545"></a>
+<span class="sourceLineNo">546</span>        }<a name="line.546"></a>
+<span class="sourceLineNo">547</span><a name="line.547"></a>
+<span class="sourceLineNo">548</span>        final double ret;<a name="line.548"></a>
+<span class="sourceLineNo">549</span>        final double t = x &lt;= 0.5 ? x : (x - 0.5) - 0.5;<a name="line.549"></a>
+<span class="sourceLineNo">550</span>        if (t &lt; 0.0) {<a name="line.550"></a>
+<span class="sourceLineNo">551</span>            final double a = INV_GAMMA1P_M1_A0 + t * INV_GAMMA1P_M1_A1;<a name="line.551"></a>
+<span class="sourceLineNo">552</span>            double b = INV_GAMMA1P_M1_B8;<a name="line.552"></a>
+<span class="sourceLineNo">553</span>            b = INV_GAMMA1P_M1_B7 + t * b;<a name="line.553"></a>
+<span class="sourceLineNo">554</span>            b = INV_GAMMA1P_M1_B6 + t * b;<a name="line.554"></a>
+<span class="sourceLineNo">555</span>            b = INV_GAMMA1P_M1_B5 + t * b;<a name="line.555"></a>
+<span class="sourceLineNo">556</span>            b = INV_GAMMA1P_M1_B4 + t * b;<a name="line.556"></a>
+<span class="sourceLineNo">557</span>            b = INV_GAMMA1P_M1_B3 + t * b;<a name="line.557"></a>
+<span class="sourceLineNo">558</span>            b = INV_GAMMA1P_M1_B2 + t * b;<a name="line.558"></a>
+<span class="sourceLineNo">559</span>            b = INV_GAMMA1P_M1_B1 + t * b;<a name="line.559"></a>
+<span class="sourceLineNo">560</span>            b = 1.0 + t * b;<a name="line.560"></a>
+<span class="sourceLineNo">561</span><a name="line.561"></a>
+<span class="sourceLineNo">562</span>            double c = INV_GAMMA1P_M1_C13 + t * (a / b);<a name="line.562"></a>
+<span class="sourceLineNo">563</span>            c = INV_GAMMA1P_M1_C12 + t * c;<a name="line.563"></a>
+<span class="sourceLineNo">564</span>            c = INV_GAMMA1P_M1_C11 + t * c;<a name="line.564"></a>
+<span class="sourceLineNo">565</span>            c = INV_GAMMA1P_M1_C10 + t * c;<a name="line.565"></a>
+<span class="sourceLineNo">566</span>            c = INV_GAMMA1P_M1_C9 + t * c;<a name="line.566"></a>
+<span class="sourceLineNo">567</span>            c = INV_GAMMA1P_M1_C8 + t * c;<a name="line.567"></a>
+<span class="sourceLineNo">568</span>            c = INV_GAMMA1P_M1_C7 + t * c;<a name="line.568"></a>
+<span class="sourceLineNo">569</span>            c = INV_GAMMA1P_M1_C6 + t * c;<a name="line.569"></a>
+<span class="sourceLineNo">570</span>            c = INV_GAMMA1P_M1_C5 + t * c;<a name="line.570"></a>
+<span class="sourceLineNo">571</span>            c = INV_GAMMA1P_M1_C4 + t * c;<a name="line.571"></a>
+<span class="sourceLineNo">572</span>            c = INV_GAMMA1P_M1_C3 + t * c;<a name="line.572"></a>
+<span class="sourceLineNo">573</span>            c = INV_GAMMA1P_M1_C2 + t * c;<a name="line.573"></a>
+<span class="sourceLineNo">574</span>            c = INV_GAMMA1P_M1_C1 + t * c;<a name="line.574"></a>
+<span class="sourceLineNo">575</span>            c = INV_GAMMA1P_M1_C + t * c;<a name="line.575"></a>
+<span class="sourceLineNo">576</span>            if (x &gt; 0.5) {<a name="line.576"></a>
+<span class="sourceLineNo">577</span>                ret = t * c / x;<a name="line.577"></a>
+<span class="sourceLineNo">578</span>            } else {<a name="line.578"></a>
+<span class="sourceLineNo">579</span>                ret = x * ((c + 0.5) + 0.5);<a name="line.579"></a>
+<span class="sourceLineNo">580</span>            }<a name="line.580"></a>
+<span class="sourceLineNo">581</span>        } else {<a name="line.581"></a>
+<span class="sourceLineNo">582</span>            double p = INV_GAMMA1P_M1_P6;<a name="line.582"></a>
+<span class="sourceLineNo">583</span>            p = INV_GAMMA1P_M1_P5 + t * p;<a name="line.583"></a>
+<span class="sourceLineNo">584</span>            p = INV_GAMMA1P_M1_P4 + t * p;<a name="line.584"></a>
+<span class="sourceLineNo">585</span>            p = INV_GAMMA1P_M1_P3 + t * p;<a name="line.585"></a>
+<span class="sourceLineNo">586</span>            p = INV_GAMMA1P_M1_P2 + t * p;<a name="line.586"></a>
+<span class="sourceLineNo">587</span>            p = INV_GAMMA1P_M1_P1 + t * p;<a name="line.587"></a>
+<span class="sourceLineNo">588</span>            p = INV_GAMMA1P_M1_P0 + t * p;<a name="line.588"></a>
+<span class="sourceLineNo">589</span><a name="line.589"></a>
+<span class="sourceLineNo">590</span>            double q = INV_GAMMA1P_M1_Q4;<a name="line.590"></a>
+<span class="sourceLineNo">591</span>            q = INV_GAMMA1P_M1_Q3 + t * q;<a name="line.591"></a>
+<span class="sourceLineNo">592</span>            q = INV_GAMMA1P_M1_Q2 + t * q;<a name="line.592"></a>
+<span class="sourceLineNo">593</span>            q = INV_GAMMA1P_M1_Q1 + t * q;<a name="line.593"></a>
+<span class="sourceLineNo">594</span>            q = 1.0 + t * q;<a name="line.594"></a>
+<span class="sourceLineNo">595</span><a name="line.595"></a>
+<span class="sourceLineNo">596</span>            double c = INV_GAMMA1P_M1_C13 + (p / q) * t;<a name="line.596"></a>
+<span class="sourceLineNo">597</span>            c = INV_GAMMA1P_M1_C12 + t * c;<a name="line.597"></a>
+<span class="sourceLineNo">598</span>            c = INV_GAMMA1P_M1_C11 + t * c;<a name="line.598"></a>
+<span class="sourceLineNo">599</span>            c = INV_GAMMA1P_M1_C10 + t * c;<a name="line.599"></a>
+<span class="sourceLineNo">600</span>            c = INV_GAMMA1P_M1_C9 + t * c;<a name="line.600"></a>
+<span class="sourceLineNo">601</span>            c = INV_GAMMA1P_M1_C8 + t * c;<a name="line.601"></a>
+<span class="sourceLineNo">602</span>            c = INV_GAMMA1P_M1_C7 + t * c;<a name="line.602"></a>
+<span class="sourceLineNo">603</span>            c = INV_GAMMA1P_M1_C6 + t * c;<a name="line.603"></a>
+<span class="sourceLineNo">604</span>            c = INV_GAMMA1P_M1_C5 + t * c;<a name="line.604"></a>
+<span class="sourceLineNo">605</span>            c = INV_GAMMA1P_M1_C4 + t * c;<a name="line.605"></a>
+<span class="sourceLineNo">606</span>            c = INV_GAMMA1P_M1_C3 + t * c;<a name="line.606"></a>
+<span class="sourceLineNo">607</span>            c = INV_GAMMA1P_M1_C2 + t * c;<a name="line.607"></a>
+<span class="sourceLineNo">608</span>            c = INV_GAMMA1P_M1_C1 + t * c;<a name="line.608"></a>
+<span class="sourceLineNo">609</span>            c = INV_GAMMA1P_M1_C0 + t * c;<a name="line.609"></a>
+<span class="sourceLineNo">610</span><a name="line.610"></a>
+<span class="sourceLineNo">611</span>            if (x &gt; 0.5) {<a name="line.611"></a>
+<span class="sourceLineNo">612</span>                ret = (t / x) * ((c - 0.5) - 0.5);<a name="line.612"></a>
+<span class="sourceLineNo">613</span>            } else {<a name="line.613"></a>
+<span class="sourceLineNo">614</span>                ret = x * c;<a name="line.614"></a>
+<span class="sourceLineNo">615</span>            }<a name="line.615"></a>
+<span class="sourceLineNo">616</span>        }<a name="line.616"></a>
+<span class="sourceLineNo">617</span><a name="line.617"></a>
+<span class="sourceLineNo">618</span>        return ret;<a name="line.618"></a>
+<span class="sourceLineNo">619</span>    }<a name="line.619"></a>
+<span class="sourceLineNo">620</span><a name="line.620"></a>
+<span class="sourceLineNo">621</span>    /**<a name="line.621"></a>
+<span class="sourceLineNo">622</span>     * Returns the value of log &amp;Gamma;(1 + x) for -0&amp;#46;5 &amp;le; x &amp;le; 1&amp;#46;5.<a name="line.622"></a>
+<span class="sourceLineNo">623</span>     * This implementation is based on the double precision implementation in<a name="line.623"></a>
+<span class="sourceLineNo">624</span>     * the &lt;em&gt;NSWC Library of Mathematics Subroutines&lt;/em&gt;, {@code DGMLN1}.<a name="line.624"></a>
+<span class="sourceLineNo">625</span>     *<a name="line.625"></a>
+<span class="sourceLineNo">626</span>     * @param x Argument.<a name="line.626"></a>
+<span class="sourceLineNo">627</span>     * @return The value of {@code log(Gamma(1 + x))}.<a name="line.627"></a>
+<span class="sourceLineNo">628</span>     * @throws NumberIsTooSmallException if {@code x &lt; -0.5}.<a name="line.628"></a>
+<span class="sourceLineNo">629</span>     * @throws NumberIsTooLargeException if {@code x &gt; 1.5}.<a name="line.629"></a>
+<span class="sourceLineNo">630</span>     * @since 3.1<a name="line.630"></a>
+<span class="sourceLineNo">631</span>     */<a name="line.631"></a>
+<span class="sourceLineNo">632</span>    public static double logGamma1p(final double x)<a name="line.632"></a>
+<span class="sourceLineNo">633</span>        throws NumberIsTooSmallException, NumberIsTooLargeException {<a name="line.633"></a>
+<span class="sourceLineNo">634</span><a name="line.634"></a>
+<span class="sourceLineNo">635</span>        if (x &lt; -0.5) {<a name="line.635"></a>
+<span class="sourceLineNo">636</span>            throw new NumberIsTooSmallException(x, -0.5, true);<a name="line.636"></a>
+<span class="sourceLineNo">637</span>        }<a name="line.637"></a>
+<span class="sourceLineNo">638</span>        if (x &gt; 1.5) {<a name="line.638"></a>
+<span class="sourceLineNo">639</span>            throw new NumberIsTooLargeException(x, 1.5, true);<a name="line.639"></a>
+<span class="sourceLineNo">640</span>        }<a name="line.640"></a>
+<span class="sourceLineNo">641</span><a name="line.641"></a>
+<span class="sourceLineNo">642</span>        return -FastMath.log1p(invGamma1pm1(x));<a name="line.642"></a>
+<span class="sourceLineNo">643</span>    }<a name="line.643"></a>
+<span class="sourceLineNo">644</span><a name="line.644"></a>
+<span class="sourceLineNo">645</span><a name="line.645"></a>
+<span class="sourceLineNo">646</span>    /**<a name="line.646"></a>
+<span class="sourceLineNo">647</span>     * Returns the value of ?(x). Based on the &lt;em&gt;NSWC Library of<a name="line.647"></a>
+<span class="sourceLineNo">648</span>     * Mathematics Subroutines&lt;/em&gt; double precision implementation,<a name="line.648"></a>
+<span class="sourceLineNo">649</span>     * {@code DGAMMA}.<a name="line.649"></a>
+<span class="sourceLineNo">650</span>     *<a name="line.650"></a>
+<span class="sourceLineNo">651</span>     * @param x Argument.<a name="line.651"></a>
+<span class="sourceLineNo">652</span>     * @return the value of {@code Gamma(x)}.<a name="line.652"></a>
+<span class="sourceLineNo">653</span>     * @since 3.1<a name="line.653"></a>
+<span class="sourceLineNo">654</span>     */<a name="line.654"></a>
+<span class="sourceLineNo">655</span>    public static double gamma(final double x) {<a name="line.655"></a>
+<span class="sourceLineNo">656</span><a name="line.656"></a>
+<span class="sourceLineNo">657</span>        if ((x == FastMath.rint(x)) &amp;&amp; (x &lt;= 0.0)) {<a name="line.657"></a>
+<span class="sourceLineNo">658</span>            return Double.NaN;<a name="line.658"></a>
+<span class="sourceLineNo">659</span>        }<a name="line.659"></a>
+<span class="sourceLineNo">660</span><a name="line.660"></a>
+<span class="sourceLineNo">661</span>        final double ret;<a name="line.661"></a>
+<span class="sourceLineNo">662</span>        final double absX = FastMath.abs(x);<a name="line.662"></a>
+<span class="sourceLineNo">663</span>        if (absX &lt;= 20.0) {<a name="line.663"></a>
+<span class="sourceLineNo">664</span>            if (x &gt;= 1.0) {<a name="line.664"></a>
+<span class="sourceLineNo">665</span>                /*<a name="line.665"></a>
+<span class="sourceLineNo">666</span>                 * From the recurrence relation<a name="line.666"></a>
+<span class="sourceLineNo">667</span>                 * Gamma(x) = (x - 1) * ... * (x - n) * Gamma(x - n),<a name="line.667"></a>
+<span class="sourceLineNo">668</span>                 * then<a name="line.668"></a>
+<span class="sourceLineNo">669</span>                 * Gamma(t) = 1 / [1 + invGamma1pm1(t - 1)],<a name="line.669"></a>
+<span class="sourceLineNo">670</span>                 * where t = x - n. This means that t must satisfy<a name="line.670"></a>
+<span class="sourceLineNo">671</span>                 * -0.5 &lt;= t - 1 &lt;= 1.5.<a name="line.671"></a>
+<span class="sourceLineNo">672</span>                 */<a name="line.672"></a>
+<span class="sourceLineNo">673</span>                double prod = 1.0;<a name="line.673"></a>
+<span class="sourceLineNo">674</span>                double t = x;<a name="line.674"></a>
+<span class="sourceLineNo">675</span>                while (t &gt; 2.5) {<a name="line.675"></a>
+<span class="sourceLineNo">676</span>                    t -= 1.0;<a name="line.676"></a>
+<span class="sourceLineNo">677</span>                    prod *= t;<a name="line.677"></a>
+<span class="sourceLineNo">678</span>                }<a name="line.678"></a>
+<span class="sourceLineNo">679</span>                ret = prod / (1.0 + invGamma1pm1(t - 1.0));<a name="line.679"></a>
+<span class="sourceLineNo">680</span>            } else {<a name="line.680"></a>
+<span class="sourceLineNo">681</span>                /*<a name="line.681"></a>
+<span class="sourceLineNo">682</span>                 * From the recurrence relation<a name="line.682"></a>
+<span class="sourceLineNo">683</span>                 * Gamma(x) = Gamma(x + n + 1) / [x * (x + 1) * ... * (x + n)]<a name="line.683"></a>
+<span class="sourceLineNo">684</span>                 * then<a name="line.684"></a>
+<span class="sourceLineNo">685</span>                 * Gamma(x + n + 1) = 1 / [1 + invGamma1pm1(x + n)],<a name="line.685"></a>
+<span class="sourceLineNo">686</span>                 * which requires -0.5 &lt;= x + n &lt;= 1.5.<a name="line.686"></a>
+<span class="sourceLineNo">687</span>                 */<a name="line.687"></a>
+<span class="sourceLineNo">688</span>                double prod = x;<a name="line.688"></a>
+<span class="sourceLineNo">689</span>                double t = x;<a name="line.689"></a>
+<span class="sourceLineNo">690</span>                while (t &lt; -0.5) {<a name="line.690"></a>
+<span class="sourceLineNo">691</span>                    t += 1.0;<a name="line.691"></a>
+<span class="sourceLineNo">692</span>                    prod *= t;<a name="line.692"></a>
+<span class="sourceLineNo">693</span>                }<a name="line.693"></a>
+<span class="sourceLineNo">694</span>                ret = 1.0 / (prod * (1.0 + invGamma1pm1(t)));<a name="line.694"></a>
+<span class="sourceLineNo">695</span>            }<a name="line.695"></a>
+<span class="sourceLineNo">696</span>        } else {<a name="line.696"></a>
+<span class="sourceLineNo">697</span>            final double y = absX + LANCZOS_G + 0.5;<a name="line.697"></a>
+<span class="sourceLineNo">698</span>            final double gammaAbs = SQRT_TWO_PI / x *<a name="line.698"></a>
+<span class="sourceLineNo">699</span>                                    FastMath.pow(y, absX + 0.5) *<a name="line.699"></a>
+<span class="sourceLineNo">700</span>                                    FastMath.exp(-y) * lanczos(absX);<a name="line.700"></a>
+<span class="sourceLineNo">701</span>            if (x &gt; 0.0) {<a name="line.701"></a>
+<span class="sourceLineNo">702</span>                ret = gammaAbs;<a name="line.702"></a>
+<span class="sourceLineNo">703</span>            } else {<a name="line.703"></a>
+<span class="sourceLineNo">704</span>                /*<a name="line.704"></a>
+<span class="sourceLineNo">705</span>                 * From the reflection formula<a name="line.705"></a>
+<span class="sourceLineNo">706</span>                 * Gamma(x) * Gamma(1 - x) * sin(pi * x) = pi,<a name="line.706"></a>
+<span class="sourceLineNo">707</span>                 * and the recurrence relation<a name="line.707"></a>
+<span class="sourceLineNo">708</span>                 * Gamma(1 - x) = -x * Gamma(-x),<a name="line.708"></a>
+<span class="sourceLineNo">709</span>                 * it is found<a name="line.709"></a>
+<span class="sourceLineNo">710</span>                 * Gamma(x) = -pi / [x * sin(pi * x) * Gamma(-x)].<a name="line.710"></a>
+<span class="sourceLineNo">711</span>                 */<a name="line.711"></a>
+<span class="sourceLineNo">712</span>                ret = -FastMath.PI /<a name="line.712"></a>
+<span class="sourceLineNo">713</span>                      (x * FastMath.sin(FastMath.PI * x) * gammaAbs);<a name="line.713"></a>
+<span class="sourceLineNo">714</span>            }<a name="line.714"></a>
+<span class="sourceLineNo">715</span>        }<a name="line.715"></a>
+<span class="sourceLineNo">716</span>        return ret;<a name="line.716"></a>
+<span class="sourceLineNo">717</span>    }<a name="line.717"></a>
+<span class="sourceLineNo">718</span>}<a name="line.718"></a>
 
 
 



Mime
View raw message