Problem with passing float to a function

My main question is, why do we have to use float at all?

Do I have to type ‘f’ after each value? Can Eclipse be configured to NOT use double as default?



Code

player.scale(1.0, 0.1, 1.0); // from the tutorial where you first time use simpleUpdate(flaot tpf)



Error

The method scale(float, float, float) in the type Spatial is not applicable for the arguments (double, double, double)



I just started jmonkeyengine and an am at the first’ish tutorials,

had a longer break from Java but that engine made me curious, so please be lentient towards me :wink:

You can answer in german if you like, i do :stuck_out_tongue:

This is normal, yeah.

It’s not Eclipse, it’s Java.

If you want floats, just put an ‘f’ after the number, as you mention (e.g. 1.1f). Integers can be automatically converted to floats, so you can type e.g. 2 without the f, but it can be a good practice to put f after floats to clearly demarcate them in your code.

Okies, i thought so allready, but the other part of the question still remains

  • why do the functions use floats if default is double?

    Does it have to do with the hardware thats used? Is float precisely enough for graphics?
@ichhassesowas said:
Okies, i thought so allready, but the other part of the question still remains
- why do the functions use floats if default is double?
Does it have to do with the hardware thats used? Is float precisely enough for graphics?


OpenGL works in floats. Floats are half the size of doubles. Float math can be cheaper than double math.

double use twice as much memory as a float, and floats precision is fine for most of the case. I guess that worth the effort of writing a f behind each decimal value.

@nehon, Ninja’d! :slight_smile:

I see, so I have to cast every single Math.sin() call etc. to float? Or are there others that return float only?

use FastMath

FastMath provides 'fast' math approximations and float equivalents of Math functions. These are all used as static values and functions.