| Issue |
172963
|
| Summary |
clang incorrectly implements real/complex division for C2y
|
| Labels |
clang
|
| Assignees |
|
| Reporter |
skirpichev
|
[C2y implementation status](https://clang.llvm.org/c_status.html#c2y) claims support for Complex operators in this standard since clang 12, but it's not true. Before [N3460](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3460.pdf), semantics for mixed-mode division with rhs complex operand was unspecified, but now it's documented (see [latest draft](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3685.pdf), §6.5.6.9):
> In the following, the real and imaginary parts of the result approximate the real and imaginary parts,
respectively, of the mathematical formula to be computed. The formulas do not indicate how the
results are to be evaluated, nor do they necessarily give desirable results when infinities or NaNs
are involved (see Annex G).
> [...]
> - The / operator where the first operand is real with value x and the second operand is complex
with value u + iv computes (xu)/(u^2 + v^2) + i(−xv)/(u^2 + v^2).
Simple reproducer:
```
$ cat a.c
#include <complex.h>
#include <stdio.h>
int main(void)
{
double x = -1.0;
double complex z = CMPLX(0, 1);
z = x/z;
printf("(%lf%+lfj)\n", creal(z), cimag(z));
return 0;
}
$ clang-19 a.c && ./a.out # (-0.000000+1.000000j) expected
(0.000000+1.000000j)
```
Maybe it's a documentation issue and fixed in the development version, but I don't think so:
https://github.com/llvm/llvm-project/blob/2c98c6ee0ec332060993ef1b529c3d6aa605d1d9/libcxx/include/complex#L839-L845
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs