How is C ++ 11 type output chosen between floats or doubles?

Consider this example of type inference:

auto var = 1.0 ; 

Does this mean for float or double when outputting type C ++ 11? Can this behavior be controlled?

+8
c ++ c ++ 11 type-inference
source share
1 answer

It will be evaluated as double and yes, you can control it.

In standard ISO-14882: 2011 , 2.14.4 Floating literals, point 1:

A floating literal type is double unless a suffix is ​​explicitly specified. The suffixes f and F indicate float, the suffixes l and L indicate a long double. If the scaled value is not in the range of displayed values ​​for its type, the program is poorly formed.

+14
source share

All Articles