What is the 'f' used for in JBox-2d? [duplicate]

两盒软妹~` 提交于 2019-12-12 05:28:53

问题


It seems to be used in value declarations in the engine but the documentation of JBox-2D does not explain what this 'unit' is. Example:

float x = 20.0f //<-- this 'f'

FixtureDef fixDef = new FixtureDef();
fixDef.shape = shape;
fixDef.density = 0.0f; //<-- this 'f'
fixDef.friction = 0.9f; //<-- this 'f'

What is it? If it is indeed a unit, what is it relative to? What benefit does it have for the engine?

EDIT: What use does it have for the engine? Is there any benefit to using a float opposed to a double?


回答1:


It is no unit, f indicates that the number is a float.

If you just write 0.1 for example, you will get an error because 0.1 will be parsed as a double value. The compiler needs the instruction that the value is desired a float. That's what's the f for.

See http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html




回答2:


It indicates that the value is a float literal.

http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html



来源:https://stackoverflow.com/questions/22180904/what-is-the-f-used-for-in-jbox-2d

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!