“ 2.00”和“ 2.00”之间在功能上有区别吗?和“ 2.00f”? [英] Is there a functional difference between "2.00" and "2.00f"?

查看:205
本文介绍了“ 2.00”和“ 2.00”之间在功能上有区别吗?和“ 2.00f”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我问是因为我正在使用Box2D库,该库主要需要float参数。尽管我看到很多使用
0.00f 格式的示例代码,但我不确定那与普通的 0.00 是否存在实际差异。以后不附加其他 f 会伤害我自己吗?是速度的东西吗?

I ask because I am using the Box2D library, which calls for mostly float arguments. Although I see a lot of example code that uses the 0.00f format, I am not quite sure if there is an actual difference between that and plain old 0.00. Will I be hurting myself later on by not appending the additional f? Is it a speed thing? Is there some sort of connotation that would need the f addend when others wouldn't?

tl; dr?是否有某种含义需要其他人不需要的 f 加数?为什么我应该使用0.00f而不是0.00?

tl;dr? Why should I be using 0.00f instead of 0.00?

推荐答案

f 后缀使它成为单精度(浮点)文字,而不是双精度文字。通常,这意味着32位而不是64位浮点数。

The f suffix makes it a single precision(float) literal instead of a double precision literal. This usually means 32 bit instead of 64 bit floats.


浮点常量的默认类型为double。通过使用后缀f或l(或F或L-后缀不区分大小写),可以将常数分别指定为float或long double。

Floating-point constants default to type double. By using the suffixes f or l (or F or L — the suffix is not case sensitive), the constant can be specified as float or long double, respectively.

http:// msdn .microsoft.com / en-us / library / tfh6f0w2(v = VS.100).aspx

这篇关于“ 2.00”和“ 2.00”之间在功能上有区别吗?和“ 2.00f”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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