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

Submitted by:  None
Submitted on:  Wed 14 Nov 2012 06:38:08 PM UTC  
 
Category: InterpreterSeverity: 3 - Normal
Priority: 5 - NormalItem Group: Matlab Compatibility
Status: InvalidAssigned to: None
Originator Name: Georgiy TreyvusOriginator Email: -unavailable-
Open/Closed: ClosedRelease: 3.2.4
Operating System: GNU/Linux

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

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>
Project 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>
Project Administrator
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 File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by godfrey (Posted a comment)
  • -unavailable- added by jordigh (Posted a comment)
  • -unavailable- added by None (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 3 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Wed 14 Nov 2012 06:45:28 PM UTCjordighItem GroupIncorrect Result=>Matlab Compatibility
      StatusNone=>Invalid
      Open/ClosedOpen=>Closed

    Back to the top


    Powered by Savane 3.1-cleanup1