[PATCH]: PR middle-end/30447 fold carg(z) -> atan2(z.i, z.r)

Richard Guenther richard.guenther@gmail.com
Wed Jan 24 16:10:00 GMT 2007


On 1/24/07, Kaveh R. GHAZI <ghazi@caip.rutgers.edu> wrote:
> This patch handles the complex function carg(z) which computes the phase
> angle of the supplied complex parameter.  This works out to:
>
> atan2(__imag__ z, __real__ z)
>
> and that's exactly what the glibc implementation does:
>
> http://www.sourceware.org/cgi-bin/cvsweb.cgi/libc/math/carg.c?rev=1.3&content-type=text/x-cvsweb-markup&cvsroot=glibc
>
> My patch folds carg to atan2 as above, regardless of whether the argument
> is constant.  This saves us one function call in the non-constant case,
> and we get compile-time evaluation of constant arguments for free through
> the atan2 builtin.  That uses mpfr_atan2 so there should be no accuracy
> concerns.
>
> Tested on sparc-sun-solaris2.10, okay for mainline?

This is ok.

Thanks,
Richard.


> 2007-01-24  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>
>
>         * builtins.c (fold_builtin_carg): New.
>         (fold_builtin_1): Use it.
>
> testsuite:
>         * gcc.dg/builtins-20.c: Test builtin carg.



More information about the Gcc-patches mailing list