Why floating point value such as 3.14 are considered as double by default in MSVC?

That’s what the C++ (and C) standard decided. Floating point literals are of type double, and if you need them to be floats, you suffix them with a f. There doesn’t appear to be any specifically stated reason as to why, but I’d guess it’s a) For compatibility with C, and b) A trade-off between precision and storage.

2.13.3 Floating literals 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.

Leave a Comment

tech