Skip to content

Commit e9b040d

Browse files
authored
Improve tgamma accuracy for negative arguments (llvm#1429)
2 parents c05828f + aa19cee commit e9b040d

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

amd/device-libs/ocml/src/tgammaF.cl

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,16 @@ MATH_MANGLE(tgamma)(float x)
4242
ret = x > 0x1.18521ep+5f ? PINF_F32 : ret;
4343
} else {
4444
float s = MATH_MANGLE(sinpi)(x);
45-
float p = s*x*t2*t1*t1;
46-
ret = MATH_DIV(-sqrtpiby2*d, MATH_MAD(p, pt, p));
47-
ret = x < -42.0f ? 0.0f : ret;
45+
if (x > -30.0f) {
46+
float p = s*x*t2*t1*t1;
47+
ret = MATH_DIV(-sqrtpiby2*d, MATH_MAD(p, pt, p));
48+
} else if (x > -41.0f) {
49+
float t3 = t2*t1;
50+
float p1 = MATH_MAD(t3, pt, t3);
51+
float p2 = s*x*t1;
52+
ret = MATH_DIV(MATH_DIV(-sqrtpiby2*d, p1), p2);
53+
} else
54+
ret = 0.0f;
4855
ret = BUILTIN_FRACTION_F32(x) == 0.0f ? QNAN_F32 : ret;
4956
}
5057
} else {

0 commit comments

Comments
 (0)