Re: Window parameters
mike wrote:
>On another note here are some solutions for int
>using a trick noted on the maximum/minimum round..
> -- simple but not the fastest
> function int(object a)
> return (floor(a)*(a>0)) - (floor(-a)*(a<0))
> end function
okay, assuming you want int to behave differently
than floor, such that:
y = floor({0.5, -1.6, 9.99, 100})
y is {0, -2, 9, 100}
versus
y = int({0.5, -1.6, 9.99, 100})
y is {0, -1, 9, 100}
then below is where you get a wee 'screwy' :)
> -- faster, more complex, allows error checking
> object temp
> temp=a
> function int_(object a)
> if atom(a) then
> if a<0 then return -floor(-a) else return floor(a) end if
> else
> for i=1 to length(a) do
> temp[i]=int_(a[i]) --***temp not declared
> end for --not needed tho...
> end if
> return temp
> end function
you could change your function to read (abbreviated):
func int_(obj a)
if atom(a) then
if a<0 then ret -floor(-a) else ret floor(a) end if
else for i=1 to length(a) do
a[i]=int_(a[i])
end for
end if
ret a
end func
but... try this instead:
function ToInt(object a)
object tmp
if atom(a) then
if a<0 then
return -floor(-a)
else return floor( a)
end if
else
for i=1 to length(a) do
tmp=a[i]
--let's save recursing the innermost seq dimension
--if it's a 10000 len seq, you saved 10000 recursions
if atom(tmp) then
if tmp<0 then
tmp=-floor(-tmp)
else tmp= floor( tmp)
end if
else tmp=ToInt(tmp) --see? now we only recurse when
end if -- its *really* needed...
a[i]=tmp
end for
return a
end function
mebbe that'll run a wee better :)
--Hawke'
|
Not Categorized, Please Help
|
|