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 & HelpPrograms › floating off float
Page Index Toggle Pages: 1
floating off float (Read 1227 times)
floating off float
May 7th, 2005, 11:03pm
 
Code:

float add = 0.04;
float wtf = 0.0;
void setup (){}
void draw (){
println(wtf);
wtf += add;
}

Code:

0.0
0.04
0.08
0.12
0.16
0.19999999
0.23999998
0.27999997
0.31999996
0.35999995
0.39999995
0.43999994
0.47999993
0.5199999
0.55999994
0.59999996
0.64
0.68
0.72
0.76000005
0.8000001
0.8400001
0.8800001
0.92000014
0.96000016
1.0000001
1.0400001
1.08
1.12

Is this normal?

I'm having severe trouble controlling the playhead of a movie file (keeps jumping back and forth). It's screwing up my whole project. I don't know if this is the cause.
Re: floating off float
Reply #1 - May 7th, 2005, 11:13pm
 
it's normal, because that's how floats work (your subject actually is closer to being correct than you might like..)

for instance if you added wtf += 0.00001; you'd never get past a certain point.

i s'pose this is something we should add to the faq since it comes up every couple months.

controlling the playhead hasn't been tested very thoroughly, so it's quite possible that there are problems. if you find something specific and reproducible, make a post in the bugs forum, and archive the sketch and post it somewhere so we can look into it.
Re: floating off float
Reply #2 - May 9th, 2005, 7:56am
 
I don't know what playhead is, but couldn't we use ints to get around this problem?
Re: floating off float
Reply #3 - May 9th, 2005, 4:03pm
 
yup, sorry i shoulda made that clear. the proper way to increment in small values like 0.0001 would be:

Code:

int incrementer;

void draw() {
incrementer++;
float wtf = (float)incrementer * 0.04;
}
Page Index Toggle Pages: 1