Open bnprks opened 9 months ago
Hello! Thank you for your very detailed report, sorry we are only starting to address algorithmic issues now.
A recent issue (#600) has pointed out the same problem in exp and pow, and similar issues in some single precision routines. However, your investigation shows that we can confidently switch the threshold without losing accuracy. Thanks a lot for doing these tests!
I will soon upload a PR with this change and add a test to catch this type of problems in the future.
The double-precision exp functions in Sleef appear to return infinity at slightly too low a value.
The current cutoff input above which Sleef returns infinity is:
709.78271114955742909217217426
However,709.78271289338399673222338991
seems to be a better cutoff.The cutoff Sleef uses is equal to
log(1.7976900000001013e+308)
, whereas the cutoff I propose is:log(1.79769313486231570815e+308)
akalog(DBL_MAX)
There are 15.3 million double-precision values between Sleef's cutoff and the one I propose. I tested all of those values on x86 SSE4 and AVX2 with the constant swapped out, and it appears that all of the return values are accurate to within 1 ULP (using
expl
withlong double
precision as the reference). This constant also exists in thepow
functions where I believe it is similarly set too low, but I'm not sure how to perform exhaustive testing to confirm raising the constant is okay.The specific line of code relevant is here, though I believe the constant should probably be adjusted in all 4 places it appears.
Testing code I used to check accuracy after adjusting the constant
```C #include