++ operator is not efficient

John W. Eaton jwe at bevo.che.wisc.edu
Mon Feb 4 11:39:38 CST 2008


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


More information about the Octave-maintainers mailing list