|
From: | Rik |
Subject: | [Octave-bug-tracker] [bug #43349] asin() behaves differently from Matlab for arguments larger than 1 |
Date: | Tue, 07 Oct 2014 05:14:58 +0000 |
User-agent: | Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:32.0) Gecko/20100101 Firefox/32.0 |
Follow-up Comment #17, bug #43349 (project octave): The phase makes a difference because x*x preserves the signbit on the imaginary portion of the product when it is zero. I tried in C++ and 2-0i * 2-0i = 4 - 0i The sqrt function distinguishes between the two phase angles -0, +0 and so the results come out different for asin (2-0i) and asin (-2+0i). I had the sign reversed in my first attempt but the attached second attempt works fine. Complex rc_asin (double x) { - return fabs (x) > 1.0 ? asin (Complex (x)) : Complex (asin (x)); + return fabs (x) > 1.0 ? asin (Complex (x, signbit (x) ? 0.0 : -0.0)) + : Complex (asin (x)); } I used the following as a reference for expected values across the branch cut: http://www.mathworks.com/help/symbolic/mupad_ref/arcsin.html#stdlib-invtrigfuncs-ex4 I think either patch will work. I tried timing them and jwe's method is 2% faster, although that is close to being noise. I tried asin on a 3000 x 3000 element matrix with the following results. rik Patch --------- 2.277 2.261 2.263 2.257 mean = 2.2645 jwe Patch --------- 2.211 2.213 2.217 2.234 mean = 2.2188 (file #32237) _______________________________________________________ Additional Item Attachment: File name: asin.patch Size:0 KB _______________________________________________________ Reply to this item at: <http://savannah.gnu.org/bugs/?43349> _______________________________________________ Message sent via/by Savannah http://savannah.gnu.org/
[Prev in Thread] | Current Thread | [Next in Thread] |