We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › what is the f in 0.1f
Page Index Toggle Pages: 1
what is the f in 0.1f? (Read 1419 times)
what is the f in 0.1f?
May 27th, 2010, 2:38pm
 
Sim sim = new Sim(0,0.1f);

I've run into this notation several times and I don't understand the f.
Re: what is the f in 0.1f?
Reply #1 - May 27th, 2010, 2:45pm
 
Java has two kinds of floating point numbers: floats and doubles.
floats have a smaller range, both in precision (number of significant digits) and in values. But they are smaller (important when you have lot of them!) and might be computed faster.
doubles have a better precision and a bigger range, but are twice as big.

In Java, 3.1415 is a double. If you want to make it a float, you write: 3.1415f or 3.1415F.
In Processing, you don't need to do that (to simplify syntax): floats are enough for most cases, so it defaults all numbers with a decimal point to floats.
Re: what is the f in 0.1f?
Reply #2 - May 28th, 2010, 9:35am
 
Cool. Was wondering about that myself. Nice explanation PhiLho!
Page Index Toggle Pages: 1