octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #43349] asin behaves differently from Matlab f


From: John W. Eaton
Subject: [Octave-bug-tracker] [bug #43349] asin behaves differently from Matlab for arguments larger than 1
Date: Mon, 06 Oct 2014 17:31:32 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0 Iceweasel/31.0

Follow-up Comment #8, bug #43349 (project octave):

Some care is needed here.  You don't want to just throw away the signbit on
the imaginary part of the argument to sqrt if it happens to be zero.  So I
think the fix belongs in rc_asin functions, not the asin (Complex) functions. 
Something like


diff --git a/liboctave/numeric/lo-mappers.cc
b/liboctave/numeric/lo-mappers.cc
--- a/liboctave/numeric/lo-mappers.cc
+++ b/liboctave/numeric/lo-mappers.cc
@@ -496,7 +496,17 @@
 Complex
 rc_asin (double x)
 {
-  return fabs (x) > 1.0 ? asin (Complex (x)) : Complex (asin (x));
+  if (fabs (x) > 1.0)
+    {
+      static Complex i (0, 1);
+
+      // Don't forward to asin (Complex (x)) because the value of
+      // Complex (1.0 - x*x) != 1.0 - (Complex (x) * Complex (x))!
+
+      return -i * log (i*x + sqrt (Complex (1.0 - x*x)));
+    }
+  else
+    return Complex (asin (x));
 }
 
 FloatComplex


We probably need to review all of these functions that convert real-valued
arguments to complex.

    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?43349>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]