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

后端 未结 7 877
轻奢々
轻奢々 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

    Typically, I don't think it will make any difference, but it is worth pointing out that 3.1415f and 3.1415 are (typically) not equal. On the other hand, you don't normally do any calculations in float anyway, at least on the usual platforms. (double is just as fast, if not faster.) About the only time you should see float is when there are large arrays, and even then, all of the calculations will typically be done in double.

提交回复
热议问题