Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit edf2210

Browse files
committed
Bug #133297: cmath.asin is the same as cmath.asinh.
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.).
1 parent cf393f3 commit edf2210

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

Modules/cmathmodule.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ static char c_acosh_doc[] =
6767
static Py_complex
6868
c_asin(Py_complex x)
6969
{
70-
Py_complex z;
71-
z = c_sqrt(c_half);
72-
z = c_log(c_prod(z, c_sum(c_sqrt(c_sum(x, c_i)),
73-
c_sqrt(c_diff(x, c_i)))));
74-
return c_sum(z, z);
70+
/* -i * log[(sqrt(1-x**2) + i*x] */
71+
const Py_complex squared = c_prod(x, x);
72+
const Py_complex sqrt_1_minus_x_sq = c_sqrt(c_diff(c_one, squared));
73+
const Py_complex sum = c_sum(sqrt_1_minus_x_sq, c_prod(c_i, x));
74+
return c_neg(c_prodi(c_log(sum)));
7575
}
7676

7777
static char c_asin_doc[] =
@@ -83,10 +83,11 @@ static char c_asin_doc[] =
8383
static Py_complex
8484
c_asinh(Py_complex x)
8585
{
86-
/* Break up long expression for WATCOM */
8786
Py_complex z;
88-
z = c_sum(c_one, c_prod(x, x));
89-
return c_log(c_sum(c_sqrt(z), x));
87+
z = c_sqrt(c_half);
88+
z = c_log(c_prod(z, c_sum(c_sqrt(c_sum(x, c_i)),
89+
c_sqrt(c_diff(x, c_i)))));
90+
return c_sum(z, z);
9091
}
9192

9293
static char c_asinh_doc[] =

0 commit comments

Comments
 (0)