There is such a thing as "floating point promotion" of float
to double
per [conv.fpprom].
A prvalue of type float
can be converted to a prvalue of type double
. The value is unchanged.
This conversion is called floating point promotion.
The answers to the linked question are correct. This promotion should not occur automatically when adding two float
s since the usual arithmetic conversions do not promote floating-point operands.
Floating point promotion does occur when passing a float
as an operand to an ellipsis, like in printf
. That's why the %f
format specifier prints either a float
or a double
: if you pass a float
, the function actually receives a double
, the result of promotion.
The existence of the floating point promotion is also important in overload resolution, because integral promotions and floating point promotions have better implicit conversion rank than integral conversions, floating point conversions, and floating-integral conversions.
Example 1:
void f(double);
void f(long double);
f(0.0f);
This calls void f(double)
since the promotion to double
is better than the conversion to long double
. In contrast, consider this perhaps surprising example 2:
void f(long double);
void f(int);
f(0.0f);
This is ambiguous. The conversion from float
to long double
is no better than the conversion from float
to int
since they are both not promotions.
Example 3:
struct S {
operator float();
operator int();
};
double d = S();
This calls operator float
and then promotes the resulting float
value to double
to initialize d
.