Re: [EuForum] Definition of insanity...
- Posted by CoJaBo <CoJaBo_EUforum_Address at CJBN.net> Nov 24, 2004
- 552 views
Pete Lomax wrote: > > On Tue, 23 Nov 2004 14:14:41 -0800, CoJaBo <guest at RapidEuphoria.com> > wrote: > > >You must never have done this: > >}}} <eucode> > >for o=1 to rand(1000000)*100 do > > --It doesnt seem to happen > > --unless the program runs for a while > >end for > >integer g > >g=time()*100 > >?g > >include get.e > >?wait_key() > ></eucode> {{{ > >Run it a few times, you'll eventually get a fairly unexpected error! > >This was the cause of headaches for many weeks before I figured it out... > > I assume you mean that: > g=floor(time()*100) > > is occasionally (and seemingly against the docs) required? > > If so, and having run the above several times, I'm slightly confused. > Compare this to: > > }}} <eucode> > if 0.1+0.2!=0.3 then > puts(1,"not equal!\n") > end if > </eucode> {{{ > > Which fails (100%) because (eg) 0.1 cannot be *exactly* represented in > binary floating point (a hardware thing, not a dig at RDS). What > confuses me is your code does not fail very often... The origanal program went unchanged for months before the problem appeared. At first it happened only about 1% of the time, but eventually increased to 95%! This change was what really confused me. Eu also kept writing garbage to ex.err, making it even more confusing! After it was finally fixed, I wanted to tar-and-feather the creater of floating point! > > Try this (failed 2dp atoms shown on the right, apologies for the line > wrap): > }}} <eucode> > procedure t100(sequence a) > integer i > for j=1 to length(a) do > i=a[j]*100 > ?i > end for > end procedure > t100({1.90,1.91,1.92,1.93,1.94,1.95,1.96,1.97,1.98,1.99, -- <none> > 2.00,2.00,2.02,2.02,2.04,2.04,2.06,2.06,2.08,2.09, --2.01, > 2.03, 2.05, 2.07 > 2.10,2.11,2.12,2.13,2.14,2.15,2.16,2.17,2.17,2.19, --2.18, > 2.21,2.21,2.21,2.23,2.23,2.25,2.25,2.27,2.27,2.29, --2.20, > 2.21, 2.24, 2.25, 2.28 > 2.29,2.29,2.29,2.29,2.34,2.34,2.36,2.36,2.38,2.38, --2.30, > 2.31, 2.32, 2.33, 2.35, 2.37, 2.39 > 2.40,2.40,2.42,2.42,2.44,2.44,2.46,2.46,2.48,2.48, --2.41, > 2.42, 2.45, 2.47, 2.48 > 2.50,2.50,2.52,2.52,2.54,2.54,2.56,2.57,2.58,2.59, --2.51, > 2.53, 2.55 > 2.60,2.61,2.62,2.63,2.64,2.65,2.66,2.67,2.68,2.69, -- <none> > 2.70,2.71,2.72,2.73,2.74,2.75,2.76,2.77,2.78,2.79}) -- <none> > </eucode> {{{ > > I am *NOT* saying this can be fixed (apart from use of floor()), > I am just exploring this in detail. > It's a fairly strange spread, if anything can be read into that... > Does anyone regularly using another language get the same results? > > Yours curiously, > Pete > >