Skip to content

Commit cbdd350

Browse files
authored
fix overflow condition
1 parent ffbc84d commit cbdd350

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/gamma.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,14 @@ function gamma(_x::Float16)
8484
s == 0 && throw(DomainError(_x, "NaN result for non-NaN input."))
8585
x = 1 - x
8686
end
87-
x > 13 && return Float16(ifelse(_x > 0, Inf32, 0f0))
88-
z = 1f0
89-
while x > 1
90-
x -= 1
91-
z *= x
92-
end
93-
num = evalpoly(x, (1.0f0, 0.4170254f0, 0.24081704f0, 0.04071509f0, 0.015839573f0))
94-
den = x*evalpoly(x, (1.0f0, 0.9942411f0, -0.17434932f0, -0.13577922f0, 0.030284522f0))
87+
x > 14 && return Float16(ifelse(_x > 0, Inf32, 0f0))
88+
z = 1f0
89+
while x > 1
90+
x -= 1
91+
z *= x
92+
end
93+
num = evalpoly(x, (1.0f0, 0.4170254f0, 0.24081704f0, 0.04071509f0, 0.015839573f0))
94+
den = x*evalpoly(x, (1.0f0, 0.9942411f0, -0.17434932f0, -0.13577922f0, 0.030284522f0))
9595
return Float16(_x < 0 ? Float32(π)*den / (s*z*num) : z * num / den)
9696
end
9797

0 commit comments

Comments
 (0)