RE: BUG! Erratic for loop behavior
- Posted by Chris Bensler <bensler at mail.com> Mar 23, 2002
- 472 views
If you change %f to %.10g it's accurate up to 8 decimal places. I think that's fairly accurate, but when yer talking math, it's not precise. Chris Chris Bensler wrote: > function magnify(atom a) > sequence str > integer f > str = sprintf("%f",a) > f = find('.',str) > if f then > a *= power(10,length(str)-f) > end if > return a > end function > > It works for up to 6 decimal places. > 34.1234567 will not be fully magnified. > > > Chris > > > Dan Moyer wrote: > > off the top of my head: > > change the vars to sequence, check for '.', count how many to right of > > '.', > > multiply by 10 to the how many for the MAX number in any var? > > > > Dan > > > > ----- Original Message ----- > > From: "Chris Bensler" <bensler at mail.com> > > To: "EUforum" <EUforum at topica.com> > > Sent: Saturday, March 23, 2002 9:02 PM > > Subject: RE: BUG! Erratic for loop behavior > > > > > > > for i = var1 to var 2 by var3 do > > > end for > > > > > > how much should the vars be multiplied by? > > > > > > Chris > > > > > > Dan Moyer wrote: > > > > Andy, > > > > > > > > Although I assume this is at least obvious, you could just do this: > > > > > > > > for i = 10*31.1 to 10*34.2 do > > > > ?i/10 > > > > end for > > > > > > > > Same for whatever max "level" of floating point you have, ie, if *any* > > > > value > > > > goes out to .001,multiply all by 1000, then divide, etc. > > > > > > > > Maybe there's some good reason that doesn't occur to me offhand why this > > > > won't work? > > > > > > > > Dan Moyer > > > > > > > > ----- Original Message ----- > > > > From: "Andy Serpa" <renegade at earthling.net> > > > > To: "EUforum" <EUforum at topica.com> > > > > Sent: Saturday, March 23, 2002 11:19 AM > > > > Subject: BUG! Erratic for loop behavior > > > > > > > > > > > > > Hello, > > > > > > > > > > > > > > > The output of this loop: > > > > > ------------------------------ > > > > > for i = 9.4 to 10.0 by .1 do > > > > > ? i > > > > > end for > > > > > ------------------------------ > > > > > stops at 10, as expected. > > > > > > > > > > > > > > > The output of this loop: > > > > > ------------------------------ > > > > > for i = 31.1 to 34.2 by .1 do > > > > > ? i > > > > > end for > > > > > ------------------------------ > > > > > stops at 34.1 (!), NOT as expected. > > > > > > > > > > > > > > > The output of this loop: > > > > > ------------------------------ > > > > > for i = 131.1 to 134.2 by .1 do > > > > > ? i > > > > > end for > > > > > ------------------------------ > > > > > stops at 134.2, as expected. > > > > > > > > > > > > > > > The output of this loop: > > > > > ------------------------------ > > > > > for i = 60.0 to 64.5 by .1 do > > > > > ? i <snip>