# bug #54491: Order of evaluation of power with unitary operators

 Submitted by: None Submitted on: Sat 11 Aug 2018 06:35:01 AM UTC Category: Interpreter Severity: 3 - Normal Priority: 3 - Low Item Group: WTF, Matlab?!? Status: Confirmed Assigned to: None Originator Name: rahnema1 Originator Email: -email is unavailable- Open/Closed: Open Release: dev Operating System: GNU/Linux

You are not logged in

Tue 28 Aug 2018 12:56:50 AM UTC, comment #5:

Marking as a low priority. I can't see the use case for this.

Rik <rik5>
Mon 13 Aug 2018 06:54:20 PM UTC, comment #4:

According to https://www.mathworks.com/help/matlab/matlab_prog/operator-precedence.html, it seems that these compound power are unary +/- operators are given some special treatment. I have no idea why. It means that an expression like

will produce a different result from

I don't see these compound operators explained in the list of operators in the Matlab docs. WTF? I don't understand why this behavior would be desirable.

Octave doesn't have these as separate operators (and I suspect that Matlab doesn't either). But when used this way in Octave, the evaluation is the same as for the power operator without the unary operator (left to right).

John W. Eaton <jwe>
Sat 11 Aug 2018 09:15:53 PM UTC, comment #3:

Copying the first 4 line into an .m function "bug54491a" (replacing function name "test" as that's an Octave function by "bug54491a") and then:

Please get yourself behind a PC with Matlab and report what Matlab does (use 'verbatim' tags, see site help to the left) before claiming Octave does it wrong.

Closing as invalid.

Philip Nienhuis <philipnienhuis>
Sat 11 Aug 2018 07:10:21 PM UTC, comment #2:

function out = test()
global a;
a = 2;
end
global a;
a = 1;
z=[7 8]
z(a) ^=- test();

I don't have MATLAB but it should work:

Evaluation order from the left to right prints 2 the order from the right to left it prints 1.
I think precedence, associativity and order of evaluation should be exactly defined so a programmer using that rules knows how to program with the programming language.

Anonymous
Sat 11 Aug 2018 06:25:47 PM UTC, comment #1:

Matlab r2018b prerelease;

This bug report isn't a strong story ... :-)

Philip Nienhuis <philipnienhuis>
Sat 11 Aug 2018 06:35:01 AM UTC, original submission:

According to the MATLAB documentation the operators (^-), (.^-), (^+), (.^+), (^~), and (.^~) work from second from the right to left but in Octave they are evaluated from the left to right.

Test case:

Anonymous

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

Comment:

No files currently attached

Depends on the following items: None found

Items that depend on this one: None found

Carbon-Copy List
• -email is unavailable- added by rik5 (Posted a comment)
• -email is unavailable- added by jwe (Posted a comment)
•

Do you think this task is very important?
This task has 0 encouragements so far.

Only project members can vote.