@Per -- it has no effect, but it can add clarity for those reading the code, particularly if some variables are double and some are float, it says "I'm intentionally, explicitly making this a float, it isn't supposed to be a double or anything else."
This is somewhat like saying "we will meet at 12:00A, midnight." 12:00A is already midnight, but you are underscoring it to make clear to the reader that this isn't a mistake and you didn't actually mean 12:00P (noon).
In this case the reader is another programmer (or yourself, later) not the compiler.
It has little effect in Processing but if you more to a Java IDE such as Eclipse or Netbeans then numbers such as 0.75 will be treated as doubles. If the compiler is expecting a float then this will cause an error e.g. we have a method that has a float parameter e,g,
void fooMethod(float n){
// do something clever here
}
then call the method with
fooMethod(0.75);
will be accepted by Processing because it adds the 'f' but rejected in Eclipse because it is a double, a different data type. You would have to do
Answers
f
->float
.d
->double
.L
->long
.PDE's pre-processor already suffixes any literal value w/
.
and/ore
in it w/f
if it doesn't have 1 already. L-)Thanks. But whats the main point of defining 0.75 as a float? :)
For example in a expression like this:
compared to
I've already said: PDE's pre-processor already takes care of auto-suffixing fractional literals w/
f
. :-<@Per -- it has no effect, but it can add clarity for those reading the code, particularly if some variables are double and some are float, it says "I'm intentionally, explicitly making this a float, it isn't supposed to be a double or anything else."
This is somewhat like saying "we will meet at 12:00A, midnight." 12:00A is already midnight, but you are underscoring it to make clear to the reader that this isn't a mistake and you didn't actually mean 12:00P (noon).
In this case the reader is another programmer (or yourself, later) not the compiler.
It has little effect in Processing but if you more to a Java IDE such as Eclipse or Netbeans then numbers such as
0.75
will be treated as doubles. If the compiler is expecting a float then this will cause an error e.g. we have a method that has a float parameter e,g,then call the method with
fooMethod(0.75);
will be accepted by Processing because it adds the 'f' but rejected in Eclipse because it is a double, a different data type. You would have to do