http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48760

--- Comment #4 from joseph at codesourcery dot com <joseph at codesourcery dot 
com> 2011-04-25 16:02:11 UTC ---
On Mon, 25 Apr 2011, paolo.carlini at oracle dot com wrote:

> A C snippet showing the issue would be:
> 
> int main()
> {
>   float r = 0;
>   float i = __builtin_nanf ("");
> 
>   __complex__ float c = r + i * 1.0fi; 
> 
>   /*
>   __complex__ float c;
>   __real__ c = r;
>   __imag__ c = i;
>   */
> 
>   __builtin_printf("%f\n", __real__ c);
>   __builtin_printf("%f\n", __imag__ c);
> }
> 
> Indeed, I could tweak the library to construct the complex by pieces, avoiding
> the multiplication by the imaginary constant in the constructor, but the
> problem would definitely reappear at any following multiplication...

I don't see any C bug here.  Without imaginary types it's correct that 
1.0fi is a complex constant and so you get NaN for both real and imaginary 
parts.  To avoid that, assign to real and imaginary parts as shown in the 
comment, or implement __builtin_cmplx* that correspond to C1X CMPLX* 
macros (which should be pretty easy to do; the built-in functions just 
need to map to COMPLEX_EXPR and handle constants correctly) and use those.

Reply via email to