-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[libc] Correct edge cases, errno, and floating point exceptions for math functions #61092
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@llvm/issue-subscribers-libc |
closing as out of date, feel free to reopen if this is still an issue. |
I checked on these and some still remain. I have fixes for some, tests for some, but I wanted to get a PR in first to add more FPMatchers that include checks for errno and exceptions.
I think it would be nice to have a programmatic way to exercise and test the different pre-processor if-groups; some of these fail the added tests in different ways depending on whether generic implementations are used. There were similar bugs with some FP depending on whether BigInt is used for float128 or not. I did want to learn more about the build, so I'm happy to work on this. We should probably also make sure we have all edge cases tested for all the math.h functions and strengthen the FP matchers to also check errno and exceptions. Some of the behavior has changed since the initial report, and it would be nice to have tests for all edge case behavior on all the math.h functions. Thoughts on a long-standing issue task list to make sure they're all tested? |
Going to open issues for the cases that still remain. |
Thanks for going through this and opening the issues! |
… macros (#88816) Adds more FP test macros for the upcoming test adds for #61092 and the issues opened from it: #88768, #88769, #88770, #88771, #88772. Fix bug in `{EXPECT,ASSERT}_FP_EXCEPTION`. `EXPECT_FP_EXCEPTION(0)` seems to be used to test that an exception did not happen, but it always does `EXPECT_GE(... & 0, 0)` which never fails. Update and refactor tests that break after the above bug fix. An interesting way things broke after the above change is that `ForceRoundingMode` and `quick_get_round()` were raising the inexact exception, breaking a lot of the `atan*` tests. The changes for all files other than `FPMatcher.h` and `libc/test/src/math/smoke/RoundToIntegerTest.h` should have the same semantics as before. For `RoundToIntegerTest.h`, lines 56-58 before the changes do not always hold since this test is used for functions with different exception and errno behavior like `lrint` and `lround`. I've deleted those lines for now, but tests for those cases should be added for the different nearest int functions to account for this. Adding @nickdesaulniers for review.
There are many cases of math functions not returning correct errno and floating point exceptions according to the C standard. The following cases are reported by Fred J. Tydeman:
log(1) = -0
forFE_DOWNWARD
logb(0)
is not raising divide-by-zerosqrt(-infinity)
=> missing errno == EDOMfmod(-NAN,-NAN) = +NAN
remainder(-infinity, -infinity)
=> no invalidnextafter(-max, -infinity)
=> no overflow, no inexactfdim(-inf, -inf)
=> invalid (should be no FP exception)fdim(-max, -den)
=> inexact (should be no FP exception)fma( -min, +min, +min )
=> missing underflowasinf()
issue: no inexactThe text was updated successfully, but these errors were encountered: