In quite a few languages, such as C # and D, 1f is a valid way to declare a floating literal, but in C ++ the closest by default is 1.f or 1.0f . However, this behavior can be implemented using C ++ 11 custom literal operators (even if this is due to a violation of the "underscore for custom literals" rule). The following program (at least in g ++ 4.9.2) works as expected, so I wonder if there is a good reason why 1f not a valid syntax for default float literals in C ++.
#include <iostream> #include <typeinfo> constexpr float operator""f(unsigned long long int i){ return static_cast<float>(i); } int main(){ auto f1 = 1f; auto f2 = 1.f; if(typeid(f1) == typeid(f2)) std::cout << "They're the same" << std::endl; return 0; }
source share