# Thread: Implicit conversion between float and double

1. ## Implicit conversion between float and double

Hi,
I'm dealing with the complex.h header and the following lines give me a warning:

Code:
```    complex double W[MAX_V];
W[1] = (1 * cos(-2. * M_PI / N)) + (I * 1 * sin(-2. * M_PI / N));```
Code:
```implicit conversion increases floating-point precision:
'_Complex float' to '_Complex double' [-Wdouble-promotion]
W[1] = (1 * cos(-2. * M_PI / N)) + (I * 1 * sin(-2. * M_PI / N));
~~^~~ ~```
I think this warning is related to those lines in complex.h, but I don't know how to fix it.

Code:
```#define _Complex_I    (__extension__ 1.0iF)

/* Another more descriptive name is `I'.
XXX Once we have the imaginary support switch this to _Imaginary_I.  */
#undef I
#define I _Complex_I```

2. Yeah, the F suffix means the expression Complex_I is a float type expression.

You can avoid the warning by not compiling with -Wdouble-promotion. In fact, I can only reproduce the problem if I compile with it.

Code:
```PS C:\Users\jk\desktop> gcc -Wall foo.c -o foo.exe -lm
PS C:\Users\jk\desktop> .\foo.exe
0.500000
PS C:\Users\jk\desktop> more foo.c
#define N 6

#include <stdio.h>
#include <math.h>
#include <complex.h>

int main(void)
{
_Complex double W[10];
W[1] = (1 * cos(-2. * M_PI / N)) + (I * 1 * sin(-2. * M_PI / N));
printf("%lf \n", __real__ W[1]);
return 0;
}

PS C:\Users\jk\desktop> gcc -Wall -Wdouble-promotion foo.c -o foo.exe -lm
foo.c: In function 'main':
foo.c:10:46: warning: implicit conversion from 'complex float' to 'complex double' to match other operand of binary expression [-Wdouble-promotion]
W[1] = (1 * cos(-2. * M_PI / N)) + (I * 1 * sin(-2. * M_PI / N));
^
PS C:\Users\jk\desktop>```
In my opinion, the warning causes more trouble than it is worth.

3. Thank you, I figured it out it wasn't a big issue since I wasn't losing precision but I wanted to be sure

4. Originally Posted by whiteflags
You can avoid the warning by not compiling with -Wdouble-promotion. In fact, I can only reproduce the problem if I compile with it.
gcc doesn't even complain with -Wall -Wextra -pedantic, so it's considered by gcc to be beyond pedantic.

BTW, you are both forgetting that M_PI is not guaranteed to be defined in math.h (sadly). Try compiling with gcc -std=c99, for instance. You need something like:
Code:
```#ifndef M_PI
#define M_PI 3.141592653589793238
#endif```