Why floating point value such as 3.14 are considered as double by default in MSVC?

前端 未结 5 1752
逝去的感伤
逝去的感伤 2020-11-27 08:27

Why do I need to put 3.14f instead of 3.14 to disable all those warnings ? Is there a coherent reason reason for this ?

5条回答
  •  温柔的废话
    2020-11-27 08:54

    This is not peculiar to MSVC, it is required by the language standard.

    I would suggest that it made sense not to reduce precision unless explicitly requested, so the default is double.

    The 6 significant digits of precision that a single-precision float provides is seldom sufficient for general use and certainly on a modern desktop processor would be used as a hand coded optimisation where the writer has determined that it is sufficient and necessary; so it makes sense that an explicit visible marker is required to specify a single-precision literal.

提交回复
热议问题