From: bbense+comp.lang.ruby.Aug.02.03@... Date: 2003-08-03T00:41:01+09:00 Subject: Re: Patches to 1.8.0p4 to add Bessel functions for those that have 'em -----BEGIN PGP SIGNED MESSAGE----- In article <20030801211205.GA1163@jupp%gmx.de>, Josef 'Jupp' Schugt wrote: >Saluton! > >* Mike Hall; 2003-08-01, 20:19 UTC: >> I agree with Josef that if we were to rewrite our own Bessels >> (etc.), we'd want someone who really knows what they are doing. I >> re-read 'What Every Computer Scientist Should Know About Floating >> Point" last night -- very scarey stuff! :-) > >There is reason to scare. Even the most trivial computations are >nontrivial when one has a closer look at them: - - There is nothing "scary" about this. What's scary is when you put perturbations like this into unstable algorithms. BTW, most of the "obvious" algorithms for solving differential equations are unstable. What unstable means in this context is that small errors grow non-linearly. > >1.upto(16) { |i| > puts 1.0 + (0.1 ** i) - 1.0 - (0.1 ** i) >} > >on my machine results in: > > 8.32667268468867e-17 > 6.93889390390723e-18 >-1.10371781159024e-16 >-1.10317571050400e-17 > 6.55095281406476e-17 >-8.22670162108899e-17 > 5.83866825033984e-17 >-6.07747148815308e-17 > 8.27403705232185e-17 > 8.27403704456703e-18 > 8.27403704133586e-19 > 8.89005823404259e-17 >-7.99277837359775e-17 >-7.99277837359901e-18 > 1.10223024625156e-16 >-1 e-16 > >The mathematical results of course all are 0. I did stop at 16 >because we have reached what is called 'machine's epsilon'. This >value is defined as the largest number that can be added to 1 without >changing the value. This means that at this point > >1.0 + (0.1 ** i) - 1.0 - (0.1 ** i) > >becomes equivalent to > >- (0.1 ** i) > - - The computational results are all "0" as well, they way to test floating point computations for equality is to see if the absolute value of their difference is less than EPS. Frankly, I don't understand how this comes as a surprise to people. You should not be allowed to use the / operator unless you understand this. - - Booker C. Bense -----BEGIN PGP SIGNATURE----- Version: 2.6.2 iQCVAwUBPyvYDWTWTAjn5N/lAQEy9AQAm+VqT2fBlAj9sGqYa1c3svaIoCWcKb4L YbCtYYmC3s4SYuscQlYxM4AK+MV9lbAqxOa9rnSiFWBuJ2iC8wemXClwVBRP2mrt DNLPCb60UeIxzre3X0Y4sdP4o93hG5uz2OFW6dWjWB37oqlntlSM/ksTjSeCLO9h 7GiFD92sSbA= =lu+k -----END PGP SIGNATURE-----