ROCm / ROCm-Device-Libs

ROCm Device Libraries
97 stars 60 forks source link

lgamma becomes inf for tiny negative values #71

Closed VinInn closed 1 year ago

VinInn commented 3 years ago

for values that corresponds to x*x ~ 0 lgamma becomes inf for negative x.

__global__ void doit(double x) {
   auto y =log(x);
   auto z1= lgamma(x);
   auto z2= lgamma(-x);
   printf ("double %a %a %a %a\n",x,y,z1,z2);
}

produces double 0x1p-472 -0x1.472a5c30ead69p+8 0x1.472a5c30ead69p+8 0x1.472a5c30ead69p+8 double 0x1p-522 -0x1.69d2a4df51d11p+8 0x1.69d2a4df51d11p+8 inf

in my opinion this is due to the code at line 273 (actually line 276). (as you quote fo x<0 lgamma(x) = log(pi/(|xsin(pix)|)) - lgamma(-x); that for tiny x becomes -2log(-x) + log(-x) = -log(-x);

b-sumner commented 3 years ago

Thanks for the report. We'll look into it.

b-sumner commented 3 years ago

Thanks again for the report. This will be fixed in a future ROCm release.

b-sumner commented 1 year ago

This has been fixed.