bugGNU Octave - Bugs: bug #37734, Octave produces incorrect results...

 
 

bug #37734: Octave produces incorrect results because it doesn't follow the normal order of operations

Submitter:  None
Submitted:  Wed 14 Nov 2012 06:38:08 PM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Invalid / Not an Octave Bug Assigned to:  None
Originator Name:  Georgiy Treyvus Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * 3.2.4
Operating System:  * GNU/Linux Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Wed 14 Nov 2012 07:21:02 PM UTC, comment #2: 

Sorry to say, this is the Matlab
behavior.

Of course, it would be better to
use more common precedence. But...

Michael Godfrey <godfrey>
Group Member
Wed 14 Nov 2012 06:45:28 PM UTC, comment #1: 

This follows Matlab behaviour. We can't change this.

Jordi GutiƩrrez Hermoso <jordigh>
Group Member
Wed 14 Nov 2012 06:38:08 PM UTC, original submission:  

Here is the bug:

octave:1> 2^3^2
ans =  64
octave:2>

The answer is supposed to be 512 yet Octave returns 64 here instead. The reason is that it's not following the correct order of operations. It evaluates the expression I fed it as (2^3)^2 as opposed to 2^(3^2) as it's supposed to if expressions were evaluated by normal order of operations. This bug isn't a big deal as I can simply feed Octave 2^(3^2) to get the correct answer. However even though the workaround is quite trivial inserting these extra parentheses is not something I should have to do. The goes against well established mathematical standards and against the behaviors of just about every other interpreter I've seen whether specialized for mathematical purposes or not.

Python:

>>> 2**3**2

512

Ruby:
irb(main):001:0> 2**3**2
=> 512

Bash:
georgiy@PANTHER:~$ echo $((2**3**2))
512

Qalculate:

> 2^3^2


  2^(3^2) = 512

R:

> 2^3^2

[1] 512

Scilab:
-->2^3^2
 ans  =
 
    512. 
 
Bc:
2^3^2
512

Please fix this to behave in accordance with mathematical norms.

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 godfrey (Posted a comment)
  • -email is unavailable- added by jordigh (Posted a comment)
  • -email is unavailable- added by None (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2012-11-14 jordigh Item GroupIncorrect Result Matlab Compatibility
        StatusNone Invalid / Not an Octave Bug
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-4b48.
    Corresponding source code