Is there a floating point literal suffix in C++ to make a number double precision?

后端 未结 4 870
耶瑟儿~
耶瑟儿~ 2021-01-04 01:26

I\'m currently working on a C++ project which does numerical calculations. The vast, vast majority of the code uses single precision floating point values and works perfectl

4条回答
  •  长发绾君心
    2021-01-04 02:01

    Like Mark said, the standard says that its a double unless its followed by an f.

    There are good reasons behind the standard and using compiler flags to get around it for convenience is bad practice.

    So, the correct approach would be:

    1. Remove the compiler flag
    2. Fix all the warnings about loss of precision when storing double values in floating point variables (add in all the f suffixes)
    3. When you need double, omit the f suffix.

    Its probably not the answer you were looking for, but it is the approach you should use if you care about the longevity of your code base.

提交回复
热议问题