Gearoid Murphy
Gearoid Murphy

Reputation: 12126

How does C++11 type inference decide between floats or doubles?

Consider this example of type inference:

auto var = 1.0 ;

Does this evaluate to a float or double under C++11 type inference?, can this behaviour be controlled?

Upvotes: 10

Views: 890

Answers (1)

Kiril Kirov
Kiril Kirov

Reputation: 38173

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

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

The type of a floating literal is double unless explicitly specified by a suffix. The suffixes f and F specify float, the suffixes l and L specify long double. If the scaled value is not in the range of representable values for its type, the program is ill-formed.

Upvotes: 15

Related Questions