@@ -990,21 +990,23 @@ IntervalResult ia_asech(IntervalResult x) {
990990// Poles at non-positive integers; minimum at x ≈ 1.4616
991991float _gpu_gamma(float z) {
992992 const float PI = 3.14159265358979;
993- if ( z < 0.5) {
994- return PI / (sin(PI * z) * _gpu_gamma(1.0 - z)) ;
995- }
996- z -= 1.0;
993+ // For z < 0.5, use reflection formula with inlined Lanczos (non-recursive)
994+ float w = z ;
995+ if (z < 0.5) w = 1.0 - z;
996+ w -= 1.0;
997997 float x = 0.99999999999980993;
998- x += 676.5203681218851 / (z + 1.0);
999- x += -1259.1392167224028 / (z + 2.0);
1000- x += 771.32342877765313 / (z + 3.0);
1001- x += -176.61502916214059 / (z + 4.0);
1002- x += 12.507343278686905 / (z + 5.0);
1003- x += -0.13857109526572012 / (z + 6.0);
1004- x += 9.9843695780195716e-6 / (z + 7.0);
1005- x += 1.5056327351493116e-7 / (z + 8.0);
1006- float t = z + 7.5;
1007- return sqrt(2.0 * PI) * pow(t, z + 0.5) * exp(-t) * x;
998+ x += 676.5203681218851 / (w + 1.0);
999+ x += -1259.1392167224028 / (w + 2.0);
1000+ x += 771.32342877765313 / (w + 3.0);
1001+ x += -176.61502916214059 / (w + 4.0);
1002+ x += 12.507343278686905 / (w + 5.0);
1003+ x += -0.13857109526572012 / (w + 6.0);
1004+ x += 9.9843695780195716e-6 / (w + 7.0);
1005+ x += 1.5056327351493116e-7 / (w + 8.0);
1006+ float t = w + 7.5;
1007+ float g = sqrt(2.0 * PI) * pow(t, w + 0.5) * exp(-t) * x;
1008+ if (z < 0.5) return PI / (sin(PI * z) * g);
1009+ return g;
10081010}
10091011
10101012// Interval gamma function
0 commit comments