octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

++ operator is not efficient


From: John W. Eaton
Subject: ++ operator is not efficient
Date: Mon, 04 Feb 2008 12:39:38 -0500

On  4-Feb-2008, hossein sajjadi wrote:

| *The ++ operator is not so efficient.*
| for example
| >a=[4,5,6]
| ans=
|     4 5 6
| >b=[2,2,2,2]
| ans=
|     2 2 2 2
| >a(b)++ ;
| >a
| ans=
| 4 6 6
| this means a(b(1))+1
| the efficient method is:
| 
| >a(b)++ should be equal
| a(b(1))+1
| a(b(2))+1
| a(b(3))+1
| a(b(4))+1
| that gives
| a(b(1))+1=a(2)+1=5+1
| a(b(2))+1=a(2)+1=5+1+1
| a(b(3))+1=a(2)+1=5+1+1+1
| a(b(4))+1=a(2)+1=5+1+1+1+1
| finally 'a' should be :
| [4 9 6]
| ++ operator will be very efficient if this method is implemented.

In Octave the definition of a post-increment expression

  EXPRESSION ++

is that it is the same as if you had written

  EXPRESSION = EXPRESSION + 1

with the added twist that the value of the post-increment exression is
the same as EXPRESSION itself (compare with the pre-increment
expression "++ EXPRESSION").

I don't think we should change that.

jwe


reply via email to

[Prev in Thread] Current Thread [Next in Thread]