From: Calamitas Date: 2007-09-02T20:32:36+09:00 Subject: Re: Bug in % (Float)? On 01/09/07, Morton Goldberg wrote: > On Sep 1, 2007, at 7:50 AM, Calamitas wrote: > You may be right, but I am not convinced. That is, I believe there > might be a way to order the calculation so that in general the errors > cancel rather than reinforce. Sure. That's what every numerical algorithm designer tries to do. But it is far from easy to do in general, and I am not at all sure if it is really possible to have the errors cancel in every case. But even if it is possible, figuring out what the best order is will likely be very expensive to do programmatically and thus not suited for a general purpose language. BTW, I just found an example where your m_mod_n function still gives the "wrong" result. 1.0 / 3125.0 == 0.00032 # => true m_mod_n(1.0, 0.00032) # => 0.000319999999999876 In this case, 1.0 / 0.00032 is not exactly 3125.0, i.e., / does not counter the approximation of 0.00032 anymore. > > The question you ask Ruby is what 1.0 % 0.1 is. That's near a > > discontinuity in %. You know that there is an error in representing > > 0.1, and it can go either side of the discontinuity. As it turns out, > > it goes on the wrong side of the discontinuity as far as you are > > concerned, but from the point of view of Ruby, that side has the > > closest floating point number. > > The question is: can Ruby's POV be changed to agree with mine? :) I > understand that you are arguing that it can't. You can change Ruby's POV, sure. It depends on what you want. The best result for every atomic operation, or the best result overall. The latter sounds ideal, but I don't believe it can be done in general. (If you can do that, I'm pretty sure you'll be famous.) The former is something that can be done and that I believe modern processors' floating point units do or try to do. It does req > > Can you accept that Ruby does % as an atomic operation as well as > > possible? > > Not yet. I have submitted the problem to Wolfram Research tech > support. There is nobody I have access to who knows more about > numerics than they do. I am waiting on their answer. > > Regards, Morton > >