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

--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
What we could for _Complex int just use the standard
(a + b*i) / (c + d*i) = (a*c + b*d) / (c*c + d*d) + ((b*c - a*d) / (c*c +
d*d))*i
which would be 6 multiplications and 2 divisions instead of the current
3 multiplications and 3 divisions.  But in order to avoid overflows we'd need
to do that all in bigger precision.  c*c + d*d for _Complex int is in [0,
LONG_LONG_MAX+1ULL] range, a*c+b*d in [-LONG_LONG_MAX+2*INT_MAX+2,
LONG_LONG_MAX+1ULL] range etc., so perhaps with some special cases we fit into
2*prec type.
For _Complex unsigned we'd also need to watch for b*c being smaller than a*d
and handle that by doing - ((a*d - b*c) / (c*c + d*d)) instead.

Reply via email to