Frictional Games Forum (read-only)

Full Version: What does the 'f' do in a script when behind a float?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Well, as the topic title asks: What does the 'f' do in a script when behind a float? Seeing it a lot, but I was unable to find out what it does so far. Huh
It's just used to state the number is a float. So if you have a float number parameter, if it's not an integer, you'll have to put an f in the back. Ex: 3.1f, 4.5f, etc.

At least I'm pretty sure that's it. Doesn't make sense either since the float is already called...
So the 'f' is not necessary, I assume?
It is not necessary, but it tells the compiler to allocate just enough space for the float.
I don't get why they bother with the int and float declarations then. :V

Actually that's a good question in general, why do high level programming languages do that? Why wouldn't there simply be a single data type for all numbers, and the ability to detect their precision to allocate the appropriate memory?
Because you need different things for different applications?

Making each data type the size of a long is stupid when you only need a number that goes up to 100 for example.

Also, if the compiler were to detect, it would slow the compiling process down, alot. And it will generally make your programs inefficient because a compiler may make mistakes.
No I mean, like with the f in this script, why not determine the data per value instead of per variable? Wouldn't it be more efficient with coding, as well as with the program since you could tell each value exactly what size it should be?
... You only use f when you punch in a literal value... you don't do that to variables.
Sorry, I meant constant values, not variables. And I didn't realize until I looked it up that you can do that in C++ and otherwise. Sorry, just a little confusion there. xD
You don't use constant values thát often in programming. Smile