# Thread: Compare a double to an integer

1. ## Compare a double to an integer

Given this code
Code:
```double x=1.00,y=2,z=4;
if (y/z||++x)
x+=y/z;
printf("%f\n",x);```
So (y/z||++x) is true if at least one expression is true, that is either (y/z)!=0 or (++x)!=0 or both. I wonder how the comparison is done? Is (y/z) be truncated to integer or 0 be promoted to double?

2. In general, when mixing integers and doubles in an expression, the integers are promoted to doubles, but they are promoted only when necessary to evaluate a specific operation (all operations occur only on equal types).

What I mean is, 1 / 3 + 0.1 will return a double, but it will do 1/3 as integer math first (since it's sooner in the order of operations), yielding 0, and then the addition happens. 0 is promoted to 0.0 and added to 0.1 to yield a final answer of 0.1

3. FYI the type promotion list is as follows:

Long double
Double
Float
Unsigned long int
Long int
Unsigned int
Int

When an operator has two differently typed operands, the lower operand on the list is promoted to be the same as the higher, even if there is the possibility to introduce errors (e.g. unsigned int - signed int does an unsigned operation.

Any argument shorter than an int is automatically promoted to an int anyway when used in a mathematical expression, even if this is unnecessary for the argument type (e.g. short + short math is actually int + int math).