Pergunta

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?

Foi útil?

Solução

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

Outras dicas

It indicates that the value is a float literal.

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

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top