https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104937

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
For
_Complex unsigned
foo (_Complex unsigned x, _Complex unsigned y)
{
  return y / x;
}

int
main ()
{
  _Complex int a = foo (6 + 43i, 6 + 43i);
  __builtin_printf ("%d %d\n", __real__ a, __imag__ a);
  return 0;
}
from what I see if xr < xi we expand it as
t=xr/xi*xr + xi
((yr*xr/xi + yi) / t) + ((yi*xr/xi - yr) / t) * i
Now, for the given numbers that is t=43 and the result is
43 / 43 + (0 - 6) / 43 * i
For signed complex that "works" by producing 1 + 0i, but for unsigned
that 0U - 6U is some huge number divided by 43.
But now that I see it, I think it doesn't work properly in most cases for
_Complex int either - for signed the xr < xi is actually done as abs(xr) <
abs(xi), so for both signed and unsigned complex xr/xi is 0, and similarly the
other case where we use xi/xr, with the only exception when xr==xi and thus
xr/xi is 1.  I bet the algorithm is well suited only for floating point...

Reply via email to