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 › bug increase with value with 2 decimals
Page Index Toggle Pages: 1
bug? increase with value with 2 decimals (Read 641 times)
bug? increase with value with 2 decimals
Nov 1st, 2005, 9:46pm
 
I'm posting this here because I dont know if it's a bug (I didn't find anything on the DB, or didn't know the right keyword to put) or if it's my mistake.

if I increase the value of a float number like 0. with a float number with two decimals like 0.01 (no problem with 0.1), the results don't seem exact.

i made a simple example to illustrate:

Code:


float value = 0;

void setup() {
framerate(20);
}

void draw() {
value = value + 0.01;
println(value);
}



the output is:

0.01
0.02
0.03
0.04
0.049999997
0.059999995
0.06999999
0.07999999
0.08999999

and so on... the results aren't as they should be. with other numbers, like 0.05, the results start to mess up sooner. is this a bug or am I missing something?

Im using P93 on mac os x 10.3.9.
Re: bug? increase with value with 2 decimals
Reply #1 - Nov 1st, 2005, 9:52pm
 
i thought i'd added this to the faq, but i guess not. see the explanation here:
http://processing.org/discourse/yabb/YaBB.cgi?board=general;action=display;num=1102374544
and here:
http://processing.org/discourse/yabb/YaBB.cgi?board=Syntax;action=display;num=1061302380
Re: bug? increase with value with 2 decimals
Reply #2 - Nov 1st, 2005, 10:37pm
 
thanks for the quickness in replying!

The explanations are a bit too complex for me though. But what I understood is that this is a java problem, and the workaround to it is by using integers and then dividing them as needed.
Page Index Toggle Pages: 1