FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Discussion
   General Processing Discussion
(Moderators: fry, REAS)
   float (im)precision?
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: float (im)precision?  (Read 519 times)
lunetta

7200475272004752 WWW Email
float (im)precision?
« on: Dec 7th, 2004, 12:09am »

Hello all
 
I'm trying to understand de concept, the reason of this:
 
double n;
void setup() {
size (500,500);
n = 0.0000;
}
void loop() {
n+=0.0002;
println(n);
}
 
Why? Can't I have the simple, beautiful numbers I asked for?
What's the source of the imprecision?
 
toxi

WWW
Re: float (im)precision?
« Reply #1 on: Dec 7th, 2004, 12:50am »

funny, how history is repeating sometimes...
 
almost exactly the same problem popped up here over a year ago...
 

http://toxi.co.uk/
lunetta

7200475272004752 WWW Email
Re: float (im)precision?
« Reply #2 on: Dec 7th, 2004, 6:14am »

that's great. Thanks Toxi, I (think) I finally understood the bug that I was having: the 2097152.0 increment value precision.
 
But I leave a question: what's the best procedure to run a sketch that will go through thousands of thousands of iterations, each one with a very small increment and not lose the precision? My sketch visualizes musical intervals, and there's a huge difference between 2.00002 and 2.00000.
 
Am I missing something?
 
fry


WWW
Re: float (im)precision?
« Reply #3 on: Dec 7th, 2004, 7:02pm »

prolly the best is to use an integer, and then divide by 10000.0 (or whatever you need) to convert back to 2.00002.
 
this is the same reason that financial institutions don't use floats or doubles when counting money
 
lunetta

7200475272004752 WWW Email
Re: float (im)precision?
« Reply #4 on: Dec 8th, 2004, 2:54am »

damn Citizen's Bank! I'm pretty sure that they "floated" all my integers there.
 
Pages: 1 

« Previous topic | Next topic »