-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Description
Straight from the documentation:
Gamma(+0) = +Inf
Gamma(-0) = -Inf
Gamma(x) = NaN for integer x < 0
Lgamma(-integer) = +Inf
Gamma(x) treats x = 0 and x = -integer differently for without proper justification. Presumably it is this way since the sign would depend on whether the negative integer (e.g. -1) is approached from above or below, and there is no way to represent that for non-positive integers except 0 (since Go supports ±0).
However, Lgamma(x) does not make this distinction and always reports the sign of Gamma(-integer) to be positive (questionable given the above point about approaching from above or below). https://play.golang.org/p/o-hiBPerYLS
I propose that this behaviour is changed to be consistent. Either both Gamma(-int) and Lgamma(-int) should return NaN or both should return ±Inf. In particular, I propose that the value is Inf and the sign is determined by the sign of the residue, i.e. Res(Gamma, -n) = (-1)**n / n!.
Adopting this convention would make the functions consistent with each other and would provide a justification for the special behaviour chosen. It would also be consistent with the expected sign given by a ratio of Gamma functions, e.g. Pochhammer(-4, 1) = Gamma(-3)/Gamma(-4) = -4, which is well defined negative number (see http://www.wolframalpha.com/input/?i=pochhammer(-4,1)). (Note I'm not suggesting the standard library must implement ratios of Gamma functions, but it would be sensible for the signs to be consistent in my opinion).