Re: BUG! Erratic for loop behavior

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

Chris,

Oh.  Didn't think about how *many* places could be multiplied into integers!
Well, I guess the idea is useful up to a point.

My code also had an error in it, besides being uninspired and not fully
thought out:

The line:
    if length(tempVar1) - PosOfDecPoint > multiplier then

should only read like that for the FIRST test, not all three; in each other
test, it should be, respectively,

   if length(tempVar2) - PosOfDecPoint > multiplier then
   if length(tempVar3) - PosOfDecPoint > multiplier then

sorry.

corrected 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(tempVar2)- PosOfDecPoint > multiplier then
      multiplier = length(tempVar2)- PosOfDecPoint
   end if
end if

PosOfDecPoint = find('.', tempVar3)
if PosOfDecPoint then
   if length(tempVar3)- 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

Dan



----- Original Message -----
From: "Chris Bensler" <bensler at mail.com>
To: "EUforum" <EUforum at topica.com>
Sent: Saturday, March 23, 2002 9:56 PM
Subject: RE: BUG! Erratic for loop behavior


>
> 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

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

Search



Quick Links

User menu

Not signed in.

Misc Menu