bugGNU Octave - Bugs: bug #56414, sin function incorrect results...

 
 

bug #56414: sin function incorrect results when not slicing input

Submitter:  Kevin Anderson <kandersondax>
Submitted:  Wed 29 May 2019 02:30:42 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Invalid / Not an Octave Bug Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * 5.1.0 Operating System:  * Microsoft Windows
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Wed 29 May 2019 03:30:11 PM UTC, comment #3: 

Thank you for the report and the discussion, but this is not a bug, this is a documented Octave feature that is intentionally slightly different from Matlab.

The important difference is that multiplying a range by a scalar returns another range. In your example, x×pi returns a new range with starting value -30×pi and step size pi. If you want to evaluate the steps as exact integers before multiplying with pi, use `pi*[x]`.

Mike Miller <mtmiller>
Group Member
Wed 29 May 2019 03:04:17 PM UTC, comment #2: 

Thank you for narrowing down our error.  While non-integer factors of pi are possible inside of sin in the "real" thing I was testing when I found this, the simple example I gave was all values of multiples of pi, as was our original test.

Still odd that different results from slicing the type though.  I would have expected the same (bad, rounding error) results both ways.

Kevin Anderson <kandersondax>
Wed 29 May 2019 02:44:56 PM UTC, comment #1: 

sin(o)=0
sin(pi)=0
sin(2*pi)=0
sin(30*pi)=0
So all your answers should be 0
What you are seeing is rounding errors because of binary representations.
Also when you do -30:-20 it is not stored as [-30 -29 -28 ...-20]
but is expanded when used. So you can see slightly different rounding errors from the 2 methods.

Doug Stewart <dastew>
Wed 29 May 2019 02:30:42 PM UTC, original submission:  

The "sin" function can be made to have different output in very specific circumstances depending on if an input vector is sliced or not.  Slicing to copy actually gives the correct result, whereas the original (or a simple copy) does not.

Here is a minimal example from Octave 5.1.0 on Windows 10 x64:


>> x = -30:-20
x =

  -30  -29  -28  -27  -26  -25  -24  -23  -22  -21  -20

>> sin(pi*x)
ans =

 Columns 1 through 9:

   1.0779e-14  -1.4209e-14   1.7640e-14  -6.8592e-15   1.0289e-14  -1.3720e-14   2.9391e-15  -6.3693e-15   9.7996e-15

 Columns 10 and 11:

  -1.3230e-14   2.4492e-15

>> sin(pi*x(1:end))
ans =

 Columns 1 through 9:

   1.0779e-14   1.3553e-18   3.4289e-15  -6.8592e-15  -3.9215e-15   4.9120e-16   2.9391e-15  -6.3693e-15   9.7996e-15

 Columns 10 and 11:

   9.8104e-16   2.4492e-15



As can be seen above, the results from columns 5, 6, and 10 differ.  The results from the x(1:end) set are correct if you type in the numbers individually.  The results from the first form where x is used directly are incorrect.  It is also only certain values this happens with, though the example above is not all of them.

The multiplication by "pi" also seems necessary for this bug to occur, but I cannot guarantee that.  I only know I've only seen it with "pi" as a factor.  This bug was also observed when multiplying by a number which was a multiple of pi as well.

Kevin Anderson <kandersondax>

 

(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 dastew (Posted a comment)
  • -email is unavailable- added by kandersondax (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 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-05-29 mtmiller StatusNone Invalid / Not an Octave Bug
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-4b48.
    Corresponding source code