What's the C++ suffix for long double literals?

独自空忆成欢 提交于 2019-11-27 20:58:56
Vlad from Moscow

From the C++ Standard

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.

It is interesting to compare with corresponding paragraph of the C Standard. In C there is used term floating constant instead of floating literal in C++:

4 An unsuffixed floating constant has type double. If suffixed by the letter f or F, it has type float. If suffixed by the letter l or L, it has type long double

The C suffix is L. I'd strongly suspect that it is the same for C++.

Your worry is justified. Your literal would first be converted to a double, and thus truncated, and then converted back to long double.

Your concern is valid and you should use a L suffix for long double literal.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!