1
0
mirror of https://gitlab.com/rnger/amath synced 2025-10-06 02:49:59 +00:00
Files
amath/doc/man/man3/csqrt.c.3
2017-01-24 22:03:15 +01:00

117 lines
2.4 KiB
Groff

.TH "lib/cplex/csqrt.c" 3 "Tue Jan 24 2017" "Version 1.6.2" "amath" \" -*- nroff -*-
.ad l
.nh
.SH NAME
lib/cplex/csqrt.c \-
.SH SYNOPSIS
.br
.PP
\fC#include 'prim\&.h'\fP
.br
\fC#include 'math\&.h'\fP
.br
\fC#include 'complex\&.h'\fP
.br
.SS "Functions"
.in +1c
.ti -1c
.RI "\fBcomplex\fP \fBcsqrt\fP (\fBcomplex\fP z)"
.br
.RI "\fISquare root of complex number\&. \fP"
.in -1c
.SH "Function Documentation"
.PP
.SS "\fBcomplex\fP csqrt (\fBcomplex\fP z)"
.PP
Square root of complex number\&.
.PP
\fBVersion:\fP
.RS 4
1\&.1
.RE
.PP
\fBDate:\fP
.RS 4
2007/08/20
.RE
.PP
.PP
Definition at line 46 of file csqrt\&.c\&.
.PP
References cabs(), cimag(), cpack(), creal(), and sqrt()\&.
.PP
Referenced by cacos(), cacosh(), cacsc(), cacsch(), casec(), casech(), casin(), casinh(), and ComplexNumber::SquareRoot()\&.
.PP
.nf
47 {
48 complex w;
49 double x, y, r, t, scale;
50
51 x = creal (z);
52 y = cimag (z);
53
54 if (y == 0\&.0) {
55 if (x == 0\&.0) {
56 w = cpack(0\&.0, y);
57 } else {
58 r = fabs(x);
59 r = sqrt(r);
60 if (x < 0\&.0) {
61 w = cpack(0\&.0, r);
62 } else {
63 w = cpack(r, y);
64 }
65 }
66 return w;
67 }
68 if (x == 0\&.0) {
69 r = fabs(y);
70 r = sqrt(0\&.5 * r);
71 if (y > 0)
72 w = cpack(r, r);
73 else
74 w = cpack(r, -r);
75 return w;
76 }
77 /* Rescale to avoid internal overflow or underflow\&. */
78 if ((fabs(x) > 4\&.0) || (fabs(y) > 4\&.0)) {
79 x *= 0\&.25;
80 y *= 0\&.25;
81 scale = 2\&.0;
82 } else {
83 #if 1
84 x *= 1\&.8014398509481984e16; /* 2^54 */
85 y *= 1\&.8014398509481984e16;
86 scale = 7\&.450580596923828125e-9; /* 2^-27 */
87 #else
88 x *= 4\&.0;
89 y *= 4\&.0;
90 scale = 0\&.5;
91 #endif
92 }
93 w = cpack(x, y);
94 r = cabs(w);
95 if (x > 0) {
96 t = sqrt(0\&.5 * r + 0\&.5 * x);
97 r = scale * fabs((0\&.5 * y) / t );
98 t *= scale;
99 } else {
100 r = sqrt(0\&.5 * r - 0\&.5 * x);
101 t = scale * fabs((0\&.5 * y) / r);
102 r *= scale;
103 }
104 if (y < 0)
105 w = cpack(t, -r);
106 else
107 w = cpack(t, r);
108 return w;
109 }
.fi
.SH "Author"
.PP
Generated automatically by Doxygen for amath from the source code\&.