Re: ABS --fastest thus far
>Ralf Nieuwenhuijsen wrote:
>>>can anyone beat carl's compare({x},{0}) suggestion?
>> May I notice compare ({x}, {0}) only has the same effect as (x>0)-(x<0)
for atoms.
>> For sequences it does *not* work. You need to use: (x>0)-(x<0)
>errrrr.... *blush*
>yer right... oopsie!
>see other post for my bestest solution (abs4)
Im not trying to brake your world, but try abs4 with this sequence: { { { 1,
1, 1}, 0, 0}, 34, }
Yours only works with one dimensional sequences.
We were kinda looking for one that did all the tricks together.. atoms, any
type of sequence, integers, etc.
If recursion works so well, lets try this one..
It is a bunch of code though.. so it doesnt win the 'simplicity' contest..
but maybe the speed..
Or is recursion by default slower than jumping to another function ?
(a difference of more than a sequence () call ?)
-- ABS.e
object temp
function abs_sequence (sequence x)
for index = 1 to lenght(x) do
temp = index[x]
if sequence(temp) then
index[x] = abs_sequence (temp)
elsif temp < 0 then
index[x] = -temp
end if
end for
end function
global function abs (object x)
if sequence (x) then
for index = 1 to length(x) do
temp = index[x]
if sequence(temp) then
index[x] = abs_sequence (temp)
elsif temp < 0 then
index[x] = -temp
end if
end for
elsif x< 0 then
return -x
else
return x
end if
end function
|
Not Categorized, Please Help
|
|