|
Author |
Topic: float (im)precision? (Read 519 times) |
|
lunetta
|
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?
|
|
|
|
lunetta
|
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
|
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
|
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.
|
|
|
|
|