-
Notifications
You must be signed in to change notification settings - Fork 140
/
s_casin.c
136 lines (122 loc) · 2.82 KB
/
s_casin.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/* $OpenBSD: s_casin.c,v 1.6 2013/07/03 04:46:36 espie Exp $ */
/*
* Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* casin()
*
* Complex circular arc sine
*
*
*
* SYNOPSIS:
*
* double complex casin();
* double complex z, w;
*
* w = casin (z);
*
*
*
* DESCRIPTION:
*
* Inverse complex sine:
*
* 2
* w = -i clog( iz + csqrt( 1 - z ) ).
*
* casin(z) = -i casinh(iz)
*
* ACCURACY:
*
* Relative error:
* arithmetic domain # trials peak rms
* DEC -10,+10 10100 2.1e-15 3.4e-16
* IEEE -10,+10 30000 2.2e-14 2.7e-15
* Larger relative error can be observed for z near zero.
* Also tested by csin(casin(z)) = z.
*/
#include <float.h>
#include <openlibm_complex.h>
#include <openlibm_math.h>
#include "math_private.h"
double complex
casin(double complex z)
{
double complex w;
static double complex ca, ct, zz, z2;
double x, y;
x = creal (z);
y = cimag (z);
if (y == 0.0) {
if (fabs(x) > 1.0) {
w = M_PI_2 + 0.0 * I;
/*mtherr ("casin", DOMAIN);*/
}
else {
w = asin (x) + 0.0 * I;
}
return (w);
}
/* Power series expansion */
/*
b = cabs(z);
if( b < 0.125 ) {
z2.r = (x - y) * (x + y);
z2.i = 2.0 * x * y;
cn = 1.0;
n = 1.0;
ca.r = x;
ca.i = y;
sum.r = x;
sum.i = y;
do {
ct.r = z2.r * ca.r - z2.i * ca.i;
ct.i = z2.r * ca.i + z2.i * ca.r;
ca.r = ct.r;
ca.i = ct.i;
cn *= n;
n += 1.0;
cn /= n;
n += 1.0;
b = cn/n;
ct.r *= b;
ct.i *= b;
sum.r += ct.r;
sum.i += ct.i;
b = fabs(ct.r) + fabs(ct.i);
}
while( b > MACHEP );
w->r = sum.r;
w->i = sum.i;
return;
}
*/
ca = x + y * I;
ct = ca * I;
/* sqrt( 1 - z*z) */
/* cmul( &ca, &ca, &zz ) */
/*x * x - y * y */
zz = (x - y) * (x + y) + (2.0 * x * y) * I;
zz = 1.0 - creal(zz) - cimag(zz) * I;
z2 = csqrt (zz);
zz = ct + z2;
zz = clog (zz);
/* multiply by 1/i = -i */
w = zz * (-1.0 * I);
return (w);
}
#if LDBL_MANT_DIG == DBL_MANT_DIG
openlibm_strong_reference(casin, casinl);
#endif /* LDBL_MANT_DIG == DBL_MANT_DIG */