[libc][math] `double` `atan2` returns positive zero when the mathematical result is a tiny negative value
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
When the mathematical result is a tiny negative value, it should underflow to negative zero under the default rounding mode. Even though `double` `atan2` isn't correctly rounded yet, I believe that it should preserve the property that the sign of `atan2(y, x)` is the same as the sign of `y`, including the sign of zeros.
```
C:\Users\He\source\temp>type atan2.cpp
```
```cpp
#include "shared/math.h"
#include
int main() {
printf("atan2 (-DBL_MIN, DBL_MAX) = %.17g\n", LIBC_NAMESPACE::shared::atan2(-DBL_MIN, DBL_MAX));
printf("atan2f(-FLT_MIN, FLT_MAX) = %.9g\n", LIBC_NAMESPACE::shared::atan2f(-FLT_MIN, FLT_MAX));
return 0;
}
```
```
C:\Users\He\source\temp>clang++ -I llvm-project\libc -std=c++23 atan2.cpp && a.exe
atan2 (-DBL_MIN, DBL_MAX) = 0
atan2f(-FLT_MIN, FLT_MAX) = -0
```
Contributor guide
Research direction
Reproduce the result with the C++ example using shared/math.h and the shown clang++ command, then trace the double atan2 entry point and compare it with atan2f. Done means atan2(-DBL_MIN, DBL_MAX) preserves the negative sign when the tiny result underflows to zero, without changing the expected behavior for the float case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 67/100