bugGNU Octave - Bugs: bug #44280, atan, atand have different phase...

 
 

bug #44280: atan, atand have different phase from other SW when outside principal branch.

Submitter:  None
Submitted:  Tue 17 Feb 2015 01:31:28 AM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Fixed Assigned to:  None
Originator Name:  jeff pantazes Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * 3.8.1
Operating System:  * Mac OS Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Tue 17 Feb 2015 04:35:03 PM UTC, comment #5: 

@Michael: You're right.  Even if other SW packages have chosen a particular phase for the return value, we need to follow Matlab's lead in this regard for compatibility.  Closing report.

Rik <rik5>
Group administrator
Tue 17 Feb 2015 04:30:43 PM UTC, comment #4: 

in Matlab 2014a:

>> atand(5i)


ans =

 -90.0000 +11.6157i

>> atan(5i)


ans =

  -1.5708 + 0.2027i

>> version


ans =

8.3.0.532 (R2014a)

Should we accept this and leave things as they are?

Michael Godfrey <godfrey>
Group Member
Tue 17 Feb 2015 04:12:42 PM UTC, comment #3: 

Thanks.  This has already been partially addressed in the development branch that will be released as Octave 4.0 within the next month or so.  The NEWS file reads


 ** The trigonometric functions asin and acos return different phase values
    from previous versions of Octave when the input is outside the principal
    branch ([-1, 1]).  If the real portion of the input is greater than 1 then
    the limit from below is taken.  If the real portion is less than 1 then the
    limit from above is taken.  This criteria is consistent with several other
    numerical analysis software packages.


However, I do note that atan (and by extension atand), do not produce the same phase.  Re-titling the bug report to reflect this remaining issue.

Rik <rik5>
Group administrator
Tue 17 Feb 2015 04:14:51 AM UTC, comment #2: 

Oh, I notice you have version 3.8.1.  The complex conjugation for asin() may be this bug

https://savannah.gnu.org/bugs/?func=detailitem&item_id=43349

that was fixed in October 2014.  So maybe this isn't as severe a problem as I thought.  So, that is atan() that has a problem (atand is derivative of atan).

Dan Sebald <sebald>
Tue 17 Feb 2015 03:31:14 AM UTC, comment #1: 

Thanks for reporting this.  I've confirmed one bug for sure.

Here's what I'm seeing on a linux system:

>> asind(3)

ans =   90.000 - 100.998i

>> atand(5i)

ans = -90.000 + 11.616i

>> atan(5i)

ans = -1.57080 + 0.20273i

>> asin(3)

ans =  1.5708 - 1.7627i

This looks to be an incorrect formula for arc tangent in liboctave/numberic/lo-mappers.c:


Complex
atan (const Complex& x)
{
  static Complex i (0, 1);

  return i * log ((i + x) / (i - x)) / 2.0;
}


I think it should be (i - x) / (i + x) in the argument of the complex logarithm.  Or i/2 * (ln(i-x) - ln(i+x)).  In the case of x=5i, something for which the argument of the logarithm is solely imaginary (i.e., -4i and 6i), the imaginary portion of the logarithm in both cases is -pi/2*i - -pi/2*i = -pi*i, multiplying by i/2 gives us pi/2, or 90 degrees.

So, yes, atand() seems like a bug.  But more than that we should have some good test cases to find these bugs, and that's a bit of a project.

But I don't know why your build of Octave is having problems with asin() as well.  Different library for the Apple products?  I don't know.  I will look into this more and try making some guesses.

Dan Sebald <sebald>
Tue 17 Feb 2015 01:31:28 AM UTC, original submission:  

GNU Octave, version 3.8.1
Octave was configured for "x86_64-apple-darwin14.1.0".

octave --eval "asind(3)" yields 90.000 + 100.998i
however wolfram alpha yields
89.999999999999...-100.9979734210524220... i
Please note the negative sign next to the imaginary number.
My personal calculations give 90 + -100.997973421052i
Again I am noting the negative sign not the rounding.

Found same for:
octave --eval "atand(5i)"
result: -90.000 + 11.616i
wolfram alpha:
89.99999999... + 11.61571971720673661409100... i
personal:
90+11.6157197172067i
note the -90 instead of 90

atan(5i)
octave: -1.57080 + 0.20273i
wolfram alpha: 1.5707963267... + 0.20273255... i
personal: 1.570796326+0.202732554i

asin(3)
octave: 1.5708 + 1.7627i
wolfram alpha: 1.570796326... -1.7627471740... i
personal: 1.570796326+-1.76274717i

Most likely I am in error, if so I apologize ahead of time.  Thanks for looking at this.



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 rik5 (Posted a comment)
  • -email is unavailable- added by sebald (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
    2015-02-17 rik5 StatusNone Fixed
        Open/ClosedOpen Closed
    2015-02-17 rik5 Summaryasin, asind, atan, and atand may have incorrect values atan, atand have different phase from other SW when outside principal branch.

    Back to the top

    Powered by Savane 3.13-d3ae.
    Corresponding source code