[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: comparing the magnitude order
From: |
CdeMills |
Subject: |
Re: comparing the magnitude order |
Date: |
Mon, 12 Sep 2011 02:10:43 -0700 (PDT) |
Bård Skaflestad wrote:
>
> On Fri, 2011-09-09 at 11:24 +0200, CdeMills wrote:
>
> You can't (directly) have branches or assignments or other things that
> affect flow of control or memory in an anonymous function constructed as
> a single statement. You can, however, achieve the desired effect by
> some creative use of function handles.
>
> For example you can, if you're inspired by functional languages, do
> something like this
>
> f = { (@(x,y) x./y), (@(x,y) y./x) }
> magn = @(x,y) f{2 - (x > y)}(x, y)
>
> Whether or not this is a good idea, readable or maintainable is largely
> in the eye of the beholder. Personally, I think I would just use your
> original max()/min() expression.
>
>
I used a lot this technique ... in the eighties. I had a pocket computer
running Basic, and IF/THEN clauses were painfully slow, while using logical
values as integer were much faster. Nothing new under the sun :-)
Thanks for the idea
Pascal
--
View this message in context:
http://octave.1599824.n4.nabble.com/comparing-the-magnitude-order-tp3801176p3806856.html
Sent from the Octave - General mailing list archive at Nabble.com.