Re: BUG! Erratic for loop behavior
- Posted by Rolf Schröder <r.schr at t-online.de> Mar 24, 2002
- 474 views
Chris Bensler wrote: > > I just did some further testing, and it seems that magnifying a decimal > value doesn't help either. > > ? magnify(0.12345678901) = 12345678901 -- 0 > ? magnify(0.12345678901) = 123456789 -- 0 > ? magnify(0.12345678901) = 12345679 -- 0 > Chris, it's the truth for all computer languages: unlimited binary numbers (like 1/1010) are not exactly representable by floating point numbers. Be aware there are even more numbers not exactly representable for calculating machines, like sqrt(2) or exp(1)... . But there are languages like 'Mathematica' or 'Derive' especially designed to fulfill so called 'algebraic computations' similar like humans do it after known rules. But they are slow and not useful for 'number crunching'. However, for the 'normal' purposes in techniques and science, it's not necessary to represent numbers exactly, it's sufficient to have a relative accuracy of 15 decimal digits. All known physical constants do have only an accuracy of about 4 to 7 decimal digits, not more! But of course one has to be careful to avoid introducing a loss of accuracy in calculations, i.e. small differences of large numbers! You may have always a small loss of accuracy in your programs, Rolf