1. Scale function (using floats)
The following function was put together to take a sequence and find the =
lowest common integer scale. Because of the heavy use of floating-point =
numbers, some of the techniques used to bypass the floating-point error =
may be useful to someone else. Note: for my purposes, I only needed =
two-decimal accuracy, so I used 100 as my multiplier. For greater =
accuracy, use a larger power of 10.
HTH,
Michael J. Sabal
mlsabal at freewwweb.com=20
---------------------------------------------------------------------------=
----------------------------------
-- Tested code follows
---------------------------------------------------------------------------=
----------------------------------
function scale_it(sequence numberlist)
sequence scale=20
atom lownum, done, divby
scale =3D repeat(0,length(numberlist))
lownum =3D power(2,32)-1 =20
done =3D 0
divby =3D 1
for a =3D 1 to length(numberlist) do
if numberlist[a] < lownum then
lownum =3D numberlist[a]
end if
end for
for b =3D 1 to length(numberlist) do
scale[b] =3D numberlist[b]/lownum
end for
while not done do
for c =3D 1 to length(scale) do
if floor(scale[c]*100) !=3D floor(scale[c])*100 then
divby =3D 1/(scale[c]-floor(scale[c]))
for d =3D 1 to length(scale) do
scale[d] =3D scale[d] * divby
end for =20
exit
end if
end for
done =3D 1
for e =3D 1 to length(scale) do
if floor(scale[e]*100) !=3D floor(scale[e])*100 then
done =3D 0
else
scale[e] =3D floor(scale[e]) -- clear all decimals since we =
have=20
-- integer precision to two places.
end if
end for
end while
return scale
end function