Re: ABS --fastest thus far

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

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

-- Time this one.. its a variant of Carl's way, I would think this one is
the fastest.

function abs (object x)
    return x + ((x < 0) + (x < 0) * x)
end function

And has any one actually timed, the manual recursive method:
I know its slower, but just how how much ?

function abs (object x)
    if sequence (x) then
        for index = 1 to length(x) do
            x[index] = abs (x[index])
        end for
    else
        if x < 0 then return -x else return x end if
    end if
end function

>can anyone beat
>   if (x<0) then return -x else return x end if
>for atoms?


Dont think thats possible..

Ralf

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

Search



Quick Links

User menu

Not signed in.

Misc Menu