Skip to content

Commit 1be7b9e

Browse files
authored
improve Float64 gamma accuracy
1 parent bd1b08d commit 1be7b9e

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/gamma.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ function gamma(_x::Float64)
55
if x < 0
66
s = sinpi(_x)
77
s == 0 && throw(DomainError(x, "NaN result for non-NaN input."))
8-
x = 1.0 - x
8+
x = -x # Use this rather than the traditional x = 1-x to avoid roundoff.
9+
s *= x
910
end
1011
if x > 11.5
1112
w = inv(x)

0 commit comments

Comments
 (0)