Re: atom = problem?
- Posted by Jason Gade <jaygade at yahoo?co?> Apr 28, 2008
- 824 views
Marco Achury wrote: > > > This happens not only on Euphoria or on PC. > In my student times, I programmed calculator CASIO FX-4000 to > solve hydraulic equations. One important step is to calculate > friction factor for using iterative method. > > Sometimes the values never converge in the same value, and mus > to check for a small difference instead check for equally. > > Change your code to: > > if abs(a - 1.8498999934219273466595723220962099730968475341796875) > < 0.000001 -- Use really needed precision > then > > +-+-+-+-+-+-+-+ > Marco A. Achury > Caracas, Venezuela Yes, depending on the magnitude of the number, there is a smallest value, epsilon, which can actually change that number when added or subtracted. I had forgotten that I had written limits.e to explore some of these concepts, with Matt's help. You can use the functions "next_higher_atom()" and "next_lower_atom" to see if your result falls into the proper window. Then again, using limits.e, I would probably do it this way:
-- untested expect = 1.849899934219273 -- better to use float64_to_atom() if you know your exact value result = tan(10.5) if abs(expect - result) > get_epsilon(result) then -- fails end if
http://www.rapideuphoria.com/limits.e -- A complex system that works is invariably found to have evolved from a simple system that works. --John Gall's 15th law of Systemantics. "Premature optimization is the root of all evil in programming." --C.A.R. Hoare j.