Re: BUG! Erratic for loop behavior

new topic     » goto parent     » topic index » view thread      » older message » newer message

Chris,

Oops, I meant "change the var which was a number into a STRING...", then
look for the decimal point in that string, then see which var has the most
places to the right of the decimal point, and use that X10 as the
multiplier.

example code:

-- begin code:

include misc.e
integer multiplier, PosOfDecPoint
multiplier = 1
PosOfDecPoint= 0

atom var1, var2, var3
var1 = 31.1
var2 = 34.25
var3 = .01

sequence tempVar1, tempVar2, tempVar3
tempVar1 = sprint(var1)
tempVar2= sprint(var2)
tempVar3 = sprint(var3)

PosOfDecPoint = find('.', tempVar1)
if PosOfDecPoint then
   if length(tempVar1) - PosOfDecPoint > multiplier then
      multiplier = length(tempVar1) - PosOfDecPoint
   end if
end if


PosOfDecPoint = find('.', tempVar2)
if PosOfDecPoint then
   if length(tempVar1) - PosOfDecPoint > multiplier then
      multiplier = length(tempVar2) - PosOfDecPoint
   end if
end if

PosOfDecPoint = find('.', tempVar3)
if PosOfDecPoint then
   if length(tempVar1) - PosOfDecPoint > multiplier then
      multiplier = length(tempVar3) - PosOfDecPoint
   end if
end if

for i = multiplier*var1 to multiplier*var2 by multiplier*var3 do
  puts(1, sprint(i/multiplier) & "   ")
end for

-- end code

Dan

----- Original Message -----
From: "Dan Moyer" <DANIELMOYER at prodigy.net>
To: "EUforum" <EUforum at topica.com>
Sent: Saturday, March 23, 2002 9:26 PM
Subject: Re: BUG! Erratic for loop behavior


>
> 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
> > > > end for
> > > > ------------------------------
> > > > stops at 64.4, NOT as expected.
> > > >
> > > >
> > > > I've verified this on exw.exe & ex.exe, as well as translated to C.
> It
> > > > looks like an outright bug to me.
> > > >
> > >

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu