]> granicus.if.org Git - python/commitdiff
Bug #133297: cmath.asin is the same as cmath.asinh.
authorTim Peters <tim.peters@gmail.com>
Wed, 21 Feb 2001 03:22:39 +0000 (03:22 +0000)
committerTim Peters <tim.peters@gmail.com>
Wed, 21 Feb 2001 03:22:39 +0000 (03:22 +0000)
The bug report title isn't correct, but was on the right track.
Rev 2.13 applied a patch intended to improve asinh and acosh, but the
author mistakenly replaced the body of asin with their new code for asinh.
See bug report for all the gory details.
This patch: (a) puts the "new" (as of 2.13) asinh code into the asinh
function; and, (b) repairs asin via what Abramowitz & Stegun say it should
be (which is probably the same as what 2.12 did for asin, although I got
tired of matching parentheses before being 100% sure of that -- and I don't
care!  The source of the old code is a mystery, and I *know* why I picked
the new code.).

Modules/cmathmodule.c

index cc7b1f0b2dae14b01f9c99ebe2268a345725b2c4..b961ca8f1a73fa42b8c3ad88214772c1abe2760c 100644 (file)
@@ -67,11 +67,11 @@ static char c_acosh_doc[] =
 static Py_complex
 c_asin(Py_complex x)
 {
-       Py_complex z;
-       z = c_sqrt(c_half);
-       z = c_log(c_prod(z, c_sum(c_sqrt(c_sum(x, c_i)),
-                                 c_sqrt(c_diff(x, c_i)))));
-       return c_sum(z, z);
+       /* -i * log[(sqrt(1-x**2) + i*x] */
+       const Py_complex squared = c_prod(x, x);
+       const Py_complex sqrt_1_minus_x_sq = c_sqrt(c_diff(c_one, squared));
+       const Py_complex sum = c_sum(sqrt_1_minus_x_sq, c_prod(c_i, x));
+        return c_neg(c_prodi(c_log(sum)));
 }
 
 static char c_asin_doc[] =
@@ -83,10 +83,11 @@ static char c_asin_doc[] =
 static Py_complex
 c_asinh(Py_complex x)
 {
-       /* Break up long expression for WATCOM */
        Py_complex z;
-       z = c_sum(c_one, c_prod(x, x));
-       return c_log(c_sum(c_sqrt(z), x));
+       z = c_sqrt(c_half);
+       z = c_log(c_prod(z, c_sum(c_sqrt(c_sum(x, c_i)),
+                                 c_sqrt(c_diff(x, c_i)))));
+       return c_sum(z, z);
 }
 
 static char c_asinh_doc[] =