diff options
author | Michael Stapelberg <stapelberg@debian.org> | 2013-03-04 21:27:36 +0100 |
---|---|---|
committer | Michael Stapelberg <michael@stapelberg.de> | 2013-03-04 21:27:36 +0100 |
commit | 04b08da9af0c450d645ab7389d1467308cfc2db8 (patch) | |
tree | db247935fa4f2f94408edc3acd5d0d4f997aa0d8 /src/pkg/math/gamma.go | |
parent | 917c5fb8ec48e22459d77e3849e6d388f93d3260 (diff) | |
download | golang-upstream/1.1_hg20130304.tar.gz |
Imported Upstream version 1.1~hg20130304upstream/1.1_hg20130304
Diffstat (limited to 'src/pkg/math/gamma.go')
-rw-r--r-- | src/pkg/math/gamma.go | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/src/pkg/math/gamma.go b/src/pkg/math/gamma.go index 7c6f421ba..164f54f33 100644 --- a/src/pkg/math/gamma.go +++ b/src/pkg/math/gamma.go @@ -110,19 +110,26 @@ func stirling(x float64) float64 { return y } -// Gamma(x) returns the Gamma function of x. +// Gamma returns the Gamma function of x. // // Special cases are: -// Gamma(±Inf) = ±Inf +// Gamma(+Inf) = +Inf +// Gamma(+0) = +Inf +// Gamma(-0) = -Inf +// Gamma(x) = NaN for integer x < 0 +// Gamma(-Inf) = NaN // Gamma(NaN) = NaN -// Large values overflow to +Inf. -// Zero and negative integer arguments return ±Inf. func Gamma(x float64) float64 { const Euler = 0.57721566490153286060651209008240243104215933593992 // A001620 // special cases switch { - case IsInf(x, -1) || IsNaN(x): - return x + case isNegInt(x) || IsInf(x, -1) || IsNaN(x): + return NaN() + case x == 0: + if Signbit(x) { + return Inf(-1) + } + return Inf(1) case x < -170.5674972726612 || x > 171.61447887182298: return Inf(1) } @@ -185,3 +192,11 @@ small: } return z / ((1 + Euler*x) * x) } + +func isNegInt(x float64) bool { + if x < 0 { + _, xf := Modf(x) + return xf == 0 + } + return false +} |