为什么在MSVC中默认情况下浮点值(如3.14)被视为双精度值? [英] Why floating point value such as 3.14 are considered as double by default in MSVC?

查看:196
本文介绍了为什么在MSVC中默认情况下浮点值(如3.14)被视为双精度值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么需要放置3.14f而不是3.14来禁用所有这些警告?
这是一个一致的原因吗?

解决方案

这是C ++(和C)浮点文字的类型为double,如果您需要它们为浮点型,则使用 f 后缀。似乎没有任何明确说明的原因,为什么,但我猜想它是a)与C兼容,和b)精度和存储之间的权衡。



2.13.3浮动文本浮动文本的类型
是double,除非后缀明确指定了

后缀f和F指定float,后缀l和L指定long double。
如果换算的值不在
范围内,那么它的类型的可表示的值,程序是不成形的。



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 ?

解决方案

That's what the C++ (and C) standard decided. Floating point literals are of type double, and if you need them to be floats, you suffix them with a f. There doesn't appear to be any specifically stated reason as to why, but I'd guess it's a) For compatibility with C, and b) A trade-off between precision and storage.

2.13.3 Floating literals 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. If the scaled value is not in the range of representable values for its type, the program is ill-formed.

这篇关于为什么在MSVC中默认情况下浮点值(如3.14)被视为双精度值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆