Add a New Comment (Rich Markup)

You are not logged in

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

@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.

in Matlab 2014a:

>> atand(5i)

ans =

-90.0000 +11.6157i

>> atan(5i)

-1.5708 + 0.2027i

>> version

8.3.0.532 (R2014a)

Should we accept this and leave things as they are?

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.

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).

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

ans = -90.000 + 11.616i

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.

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.

(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

Do you think this task is very important?If so, you can 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.

Copyright © 2019 Free Software Foundation, Inc. Verbatim copying and distribution of this entire article is permitted in any medium, provided this notice is preserved. The Levitating, Meditating, Flute-playing Gnu logo is a GNU GPL'ed image provided by the Nevrax Design Team. Source Code

Powered by Savane 3.5