Should we generally use float literals for floats instead of the simpler double literals?

后端 未结 7 822
轻奢々
轻奢々 2020-11-29 04:47

In C++ (or maybe only our compilers VC8 and VC10) 3.14 is a double literal and 3.14f is a float literal.

Now I have a colleague

相关标签:
7条回答
  • 2020-11-29 05:22

    There is a difference: If you use a double constant and multiply it with a float variable, the variable is converted into double first, the calculation is done in double, and then the result is converted into float. While precision isn't really a problem here, this might lead to confusion.

    0 讨论(0)
提交回复
热议问题