Re: Fastest Way to...

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

pos = { 3, -1, 0 }

mask = (pos > 0)
pos -= (pos * mask)
pos += mask

or

mask = (pos > 0)
pos *= (mask = 0)
pos += mask

        Lucius L. Hilley III

----- Original Message ----- 
From: "C. K. Lester" <euphoric at cklester.com>
To: <EUforum at topica.com>
Sent: Monday, October 27, 2003 09:24 PM
Subject: Fastest Way to...


> 
> 
> I've got a 3-element sequence...
> 
>     { 3, -1, 0 }
> 
> and need to turn it into this
> 
>     { 1, -1, 0 }
> 
> That is, any positive values ( > 0 ) should be turned to one.
> 
> What's the fastest way to do this? Right now I'm using
> 
>     if pos[1] > 0 then
>        pos[1] = 1
>     end if
>     if pos[2] > 0 then
>        pos[2] = 1
>     end if
>     if pos[3] > 0 then
>        pos[3] = 1
>     end if
> 
> I have a feeling this is fastest. Will it be as fast if put in a loop 
> for arbitrary length?
> 
> 
> 
> TOPICA - Start your own email discussion group. FREE!
> 
>

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

Search



Quick Links

User menu

Not signed in.

Misc Menu