1 /* origin: OpenBSD /usr/src/lib/libm/src/s_casin.c */
3 * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net>
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 * Complex circular arc sine
23 * double complex casin();
24 * double complex z, w;
31 * Inverse complex sine:
34 * w = -i clog( iz + csqrt( 1 - z ) ).
36 * casin(z) = -i casinh(iz)
41 * arithmetic domain # trials peak rms
42 * DEC -10,+10 10100 2.1e-15 3.4e-16
43 * IEEE -10,+10 30000 2.2e-14 2.7e-15
44 * Larger relative error can be observed for z near zero.
45 * Also tested by csin(casin(z)) = z.
50 double complex casin(double complex z)
53 static double complex ca, ct, zz, z2;
63 w = asin(x) + 0.0 * I;
67 /* Power series expansion */
71 z2.r = (x - y) * (x + y);
81 ct.r = z2.r * ca.r - z2.i * ca.i;
82 ct.i = z2.r * ca.i + z2.i * ca.r;
96 b = fabs(ct.r) + fabs(ct.i);
108 /* cmul(&ca, &ca, &zz) */
110 // FIXME: 1 - ()() - () I
111 zz = (x - y) * (x + y) + (2.0 * x * y) * I;
112 zz = 1.0 - creal(zz) - cimag(zz) * I;
116 /* multiply by 1/i = -i */