amath/src/cplex/amathi.3

1752 lines
33 KiB
Groff

.\" Copyright (c) 2014-2021 Carsten Sonne Larsen <cs@innolan.net>
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.TH "mathi.h" 3 "Version 1.8.5" "August 07 2018"
.SH NAME
mathi.h \- Complex numbers math library
.SH SYNOPSIS
.br
.SS "Data Structures"
.in +1c
.ti -1c
.RI "union \fBcomplex\fP"
.br
.in -1c
.SS "Functions"
.in +1c
.ti -1c
.RI "double \fBcsgn\fP (\fBcomplex\fP z)"
.br
.RI "\fIComplex signum\&. \fP"
.ti -1c
.RI "double \fBcabs\fP (\fBcomplex\fP z)"
.br
.RI "\fIAbsolute value of complex number\&. \fP"
.ti -1c
.RI "double \fBcreal\fP (\fBcomplex\fP z)"
.br
.RI "\fIReal part of complex number\&. \fP"
.ti -1c
.RI "double \fBcimag\fP (\fBcomplex\fP z)"
.br
.RI "\fIImaginary part of complex number\&. \fP"
.ti -1c
.RI "\fBcomplex\fP \fBcpack\fP (double x, double y)"
.br
.RI "\fIPack two real numbers into a complex number\&. \fP"
.ti -1c
.RI "\fBcomplex\fP \fBcadd\fP (\fBcomplex\fP a, \fBcomplex\fP z)"
.br
.RI "\fIAddition of two complex numbers\&. \fP"
.ti -1c
.RI "\fBcomplex\fP \fBcsub\fP (\fBcomplex\fP a, \fBcomplex\fP z)"
.br
.RI "\fISubtraction of two complex numbers\&. \fP"
.ti -1c
.RI "\fBcomplex\fP \fBcmul\fP (\fBcomplex\fP a, \fBcomplex\fP z)"
.br
.RI "\fIMultiplication of two complex numbers\&. \fP"
.ti -1c
.RI "\fBcomplex\fP \fBcdiv\fP (\fBcomplex\fP a, \fBcomplex\fP z)"
.br
.RI "\fIDivision of two complex numbers\&. \fP"
.ti -1c
.RI "\fBcomplex\fP \fBcpow\fP (\fBcomplex\fP x, \fBcomplex\fP z)"
.br
.RI "\fIComplex number raised to a power\&. \fP"
.ti -1c
.RI "\fBcomplex\fP \fBcceil\fP (\fBcomplex\fP z)"
.br
.RI "\fICeiling value of complex number\&. \fP"
.ti -1c
.RI "\fBcomplex\fP \fBcfloor\fP (\fBcomplex\fP z)"
.br
.RI "\fIFloor value of complex number\&. \fP"
.ti -1c
.RI "\fBcomplex\fP \fBctrunc\fP (\fBcomplex\fP z)"
.br
.RI "\fITruncated value of complex number\&. \fP"
.ti -1c
.RI "\fBcomplex\fP \fBcround\fP (\fBcomplex\fP z)"
.br
.RI "\fIDivision of two complex numbers\&. \fP"
.ti -1c
.RI "\fBcomplex\fP \fBcreci\fP (\fBcomplex\fP z)"
.br
.RI "\fIReciprocal value of complex number\&. \fP"
.ti -1c
.RI "\fBcomplex\fP \fBconj\fP (\fBcomplex\fP z)"
.br
.ti -1c
.RI "\fBcomplex\fP \fBcexp\fP (\fBcomplex\fP z)"
.br
.RI "\fIReturns e to the power of a complex number\&. \fP"
.ti -1c
.RI "\fBcomplex\fP \fBcsqrt\fP (\fBcomplex\fP z)"
.br
.RI "\fISquare root of complex number\&. \fP"
.ti -1c
.RI "\fBcomplex\fP \fBccbrt\fP (\fBcomplex\fP z)"
.br
.RI "\fICube root of complex number\&. \fP"
.ti -1c
.RI "\fBcomplex\fP \fBclog\fP (\fBcomplex\fP z)"
.br
.RI "\fINatural logarithm of a complex number\&. \fP"
.ti -1c
.RI "\fBcomplex\fP \fBclogb\fP (\fBcomplex\fP z)"
.br
.RI "\fIBase 2 logarithmic value of complex number\&. \fP"
.ti -1c
.RI "\fBcomplex\fP \fBclog10\fP (\fBcomplex\fP z)"
.br
.RI "\fIBase 10 logarithmic value of complex number\&. \fP"
.ti -1c
.RI "\fBcomplex\fP \fBccos\fP (\fBcomplex\fP z)"
.br
.RI "\fICosine of complex number\&. \fP"
.ti -1c
.RI "\fBcomplex\fP \fBcsin\fP (\fBcomplex\fP z)"
.br
.RI "\fISine of a complex number\&. \fP"
.ti -1c
.RI "\fBcomplex\fP \fBctan\fP (\fBcomplex\fP z)"
.br
.RI "\fITangent of a complex number\&. \fP"
.ti -1c
.RI "\fBcomplex\fP \fBcsec\fP (\fBcomplex\fP z)"
.br
.RI "\fISecant of a complex number\&. \fP"
.ti -1c
.RI "\fBcomplex\fP \fBccsc\fP (\fBcomplex\fP z)"
.br
.RI "\fICosecant of a complex number\&. \fP"
.ti -1c
.RI "\fBcomplex\fP \fBccot\fP (\fBcomplex\fP z)"
.br
.RI "\fICotangent of a complex number\&. \fP"
.ti -1c
.RI "\fBcomplex\fP \fBcacos\fP (\fBcomplex\fP z)"
.br
.RI "\fIInverse cosine of complex number\&. \fP"
.ti -1c
.RI "\fBcomplex\fP \fBcasin\fP (\fBcomplex\fP z)"
.br
.RI "\fIInverse sine of complex number\&. \fP"
.ti -1c
.RI "\fBcomplex\fP \fBcatan\fP (\fBcomplex\fP z)"
.br
.RI "\fIInverse tangent of complex number\&. \fP"
.ti -1c
.RI "\fBcomplex\fP \fBcasec\fP (\fBcomplex\fP z)"
.br
.RI "\fIInverse secant expressed using complex logarithms: \fP"
.ti -1c
.RI "\fBcomplex\fP \fBcacsc\fP (\fBcomplex\fP z)"
.br
.RI "\fIInverse cosecant of complex number\&. \fP"
.ti -1c
.RI "\fBcomplex\fP \fBcacot\fP (\fBcomplex\fP z)"
.br
.RI "\fIInverse cotangent of complex number\&. \fP"
.ti -1c
.RI "\fBcomplex\fP \fBccosh\fP (\fBcomplex\fP z)"
.br
.RI "\fIHyperbolic cosine of a complex number\&. \fP"
.ti -1c
.RI "\fBcomplex\fP \fBcsinh\fP (\fBcomplex\fP z)"
.br
.RI "\fIHyperbolic sine of a complex number\&. \fP"
.ti -1c
.RI "\fBcomplex\fP \fBctanh\fP (\fBcomplex\fP z)"
.br
.RI "\fIHyperbolic tangent of a complex number\&. \fP"
.ti -1c
.RI "\fBcomplex\fP \fBcsech\fP (\fBcomplex\fP z)"
.br
.RI "\fIHyperbolic secant of a complex number\&. \fP"
.ti -1c
.RI "\fBcomplex\fP \fBccsch\fP (\fBcomplex\fP z)"
.br
.RI "\fIHyperbolic secant of a complex number\&. \fP"
.ti -1c
.RI "\fBcomplex\fP \fBccoth\fP (\fBcomplex\fP z)"
.br
.RI "\fIHyperbolic cotangent of a complex number\&. \fP"
.ti -1c
.RI "\fBcomplex\fP \fBcacosh\fP (\fBcomplex\fP z)"
.br
.RI "\fIInverse hyperbolic cosine of complex number\&. \fP"
.ti -1c
.RI "\fBcomplex\fP \fBcasinh\fP (\fBcomplex\fP z)"
.br
.RI "\fIInverse hyperbolic sine of complex number\&. \fP"
.ti -1c
.RI "\fBcomplex\fP \fBcatanh\fP (\fBcomplex\fP z)"
.br
.RI "\fIInverse hyperbolic tangent of complex number\&. \fP"
.ti -1c
.RI "\fBcomplex\fP \fBcasech\fP (\fBcomplex\fP z)"
.br
.RI "\fIInverse hyperbolic secant of complex numbers\&. \fP"
.ti -1c
.RI "\fBcomplex\fP \fBcacsch\fP (\fBcomplex\fP z)"
.br
.RI "\fIInverse hyperbolic cosecant of complex number\&. \fP"
.ti -1c
.RI "\fBcomplex\fP \fBcacoth\fP (\fBcomplex\fP z)"
.br
.RI "\fIInverse hyperbolic cotangent of complex number\&. \fP"
.in -1c
.SH "Detailed Description"
.PP
Functions for handling complex numbers\&.
Mostly as specified in IEEE Std 1003\&.1, 2013 Edition:
.br
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/complex.h.html
.PP
Definition in file \fBmathi\&.h\fP\&.
.SH "Function Documentation"
.PP
.SS "double cabs (\fBcomplex\fP z)"
.PP
Absolute value of complex number\&.
.PP
Definition at line 57 of file prim\&.c\&.
.PP
.nf
58 {
59 return hypot(creal(z), cimag(z));
60 }
.fi
.SS "\fBcomplex\fP cacos (\fBcomplex\fP z)"
.PP
Inverse cosine of complex number\&.
.PP
\fBVersion:\fP
.RS 4
1\&.0
.RE
.PP
\fBDate:\fP
.RS 4
14/09/15
.RE
.PP
Inverse cosine expressed using complex logarithms:
.PP
.nf
arccos z = -i * log(z + i * sqrt(1 - z * z))
.fi
.PP
More info is available at Wikipedia:
.br
https://wikipedia.org/wiki/Inverse_trigonometric_functions#Logarithmic_forms
.PP
Definition at line 44 of file cacos\&.c\&.
.PP
.nf
45 {
46 complex a = cpack(1\&.0, 0\&.0);
47 complex i = cpack(0\&.0, 1\&.0);
48 complex j = cpack(0\&.0, -1\&.0);
49 complex p = csub(a, cmul(z, z));
50 complex q = clog(cadd(z, cmul(i, csqrt(p))));
51 complex w = cmul(j, q);
52 return w;
53 }
.fi
.SS "\fBcomplex\fP cacosh (\fBcomplex\fP z)"
.PP
Inverse hyperbolic cosine of complex number\&.
.PP
\fBVersion:\fP
.RS 4
1\&.1
.RE
.PP
\fBDate:\fP
.RS 4
15/03/03
.RE
.PP
Inverse hyperbolic cosine expressed using complex logarithms:
.PP
.nf
acosh(z) = log(z + sqrt(z*z - 1))
.fi
.PP
More info is available at Wikipedia:
.br
https://wikipedia.org/wiki/Inverse_hyperbolic_function#Logarithmic_representation
.PP
Definition at line 44 of file cacosh\&.c\&.
.PP
.nf
45 {
46 complex one = cpack(1\&.0, 0\&.0);
47 complex a = csub(cmul(z, z), one);
48 complex b = cadd(z, csqrt(a));
49 complex w = clog(b);
50 return w;
51 }
.fi
.SS "\fBcomplex\fP cacot (\fBcomplex\fP z)"
.PP
Inverse cotangent of complex number\&.
.PP
\fBVersion:\fP
.RS 4
1\&.1
.RE
.PP
\fBDate:\fP
.RS 4
14/10/01
.RE
.PP
Inverse cotangent expressed using complex logarithms:
.PP
.nf
arccot z = i/2 * (log(1 - i/z) - log(1 + i/z))
.fi
.PP
More info is available at Wikipedia:
.br
https://wikipedia.org/wiki/Inverse_trigonometric_functions#Logarithmic_forms
.PP
Definition at line 44 of file cacot\&.c\&.
.PP
.nf
45 {
46 complex one = cpack(1\&.0, 0\&.0);
47 complex two = cpack(2\&.0, 0\&.0);
48 complex i = cpack(0\&.0, 1\&.0);
49 complex iz = cdiv(i, z);
50 complex p = clog(csub(one, iz));
51 complex q = clog(cadd(one, iz));
52 complex w = cmul(cdiv(i, two), csub(p, q));
53 return w;
54 }
.fi
.SS "\fBcomplex\fP cacoth (\fBcomplex\fP z)"
.PP
Inverse hyperbolic cotangent of complex number\&.
.PP
\fBVersion:\fP
.RS 4
1\&.0
.RE
.PP
\fBDate:\fP
.RS 4
14/09/15
.RE
.PP
Inverse hyperbolic cotangent expressed using complex logarithms:
.PP
.nf
acoth(z) = 1/2 * ((log(z + 1) - log(z - 1))
.fi
.PP
More info is available at Wikipedia:
.br
https://wikipedia.org/wiki/Inverse_hyperbolic_function#Logarithmic_representation
.PP
Definition at line 44 of file cacoth\&.c\&.
.PP
.nf
45 {
46 complex half = cpack(0\&.5, 0\&.0);
47 complex one = cpack(1\&.0, 0\&.0);
48 complex a = clog(cadd(z, one));
49 complex b = clog(csub(z, one));
50 complex c = csub(a, b);
51 complex w = cmul(half, c);
52 return w;
53 }
.fi
.SS "\fBcomplex\fP cacsc (\fBcomplex\fP z)"
.PP
Inverse cosecant of complex number\&.
.PP
\fBVersion:\fP
.RS 4
1\&.1
.RE
.PP
\fBDate:\fP
.RS 4
14/10/01
.RE
.PP
Inverse cosecant expressed using complex logarithms:
.PP
.nf
arccsc z = -i * log(sqr(1 - 1/(z*z)) + i/z)
.fi
.PP
More info is available at Wikipedia:
.br
https://wikipedia.org/wiki/Inverse_trigonometric_functions#Logarithmic_forms
.PP
Definition at line 44 of file cacsc\&.c\&.
.PP
.nf
45 {
46 complex one = cpack(1\&.0, 0\&.0);
47 complex i = cpack(0\&.0, 1\&.0);
48 complex j = cpack(0\&.0, -1\&.0);
49 complex iz = cdiv(i, z);
50 complex z2 = cmul(z, z);
51 complex p = cdiv(one, z2);
52 complex q = csqrt(csub(one, p));
53 complex w = cmul(j, clog(cadd(q, iz)));
54 return w;
55 }
.fi
.SS "\fBcomplex\fP cacsch (\fBcomplex\fP z)"
.PP
Inverse hyperbolic cosecant of complex number\&.
.PP
\fBVersion:\fP
.RS 4
1\&.0
.RE
.PP
\fBDate:\fP
.RS 4
14/09/15
.RE
.PP
Inverse hyperbolic cosecant expressed using complex logarithms:
.PP
.nf
acsch(z) = log(sqrt(1 + 1 / (z * z)) + 1/z)
.fi
.PP
More info is available at Wikipedia:
.br
https://wikipedia.org/wiki/Inverse_hyperbolic_function#Logarithmic_representation
.PP
Definition at line 44 of file cacsch\&.c\&.
.PP
.nf
45 {
46 complex one = cpack(1\&.0, 0\&.0);
47 complex a = creci(cmul(z, z));
48 complex b = csqrt(cadd(one, a));
49 complex c = cadd(b, creci(z));
50 complex w = clog(c);
51 return w;
52 }
.fi
.SS "\fBcomplex\fP cadd (\fBcomplex\fP a, \fBcomplex\fP z)"
.PP
Addition of two complex numbers\&.
.PP
Definition at line 129 of file prim\&.c\&.
.PP
.nf
130 {
131 complex w;
132 w = cpack(creal(y) + creal(z), cimag(y) + cimag(z));
133 return w;
134 }
.fi
.SS "\fBcomplex\fP casec (\fBcomplex\fP z)"
.PP
Inverse secant expressed using complex logarithms:
.PP
\fBVersion:\fP
.RS 4
1\&.1
.RE
.PP
\fBDate:\fP
.RS 4
14/10/01
.RE
.PP
Inverse secant expressed using complex logarithms:
.PP
.nf
arcsec z = -i * log(i * sqr(1 - 1/(z*z)) + 1/z)
.fi
.PP
More info is available at Wikipedia:
.br
https://wikipedia.org/wiki/Inverse_trigonometric_functions#Logarithmic_forms
.PP
Definition at line 44 of file casec\&.c\&.
.PP
.nf
45 {
46 complex one = cpack(1\&.0, 0\&.0);
47 complex i = cpack(0\&.0, 1\&.0);
48 complex j = cpack(0\&.0, -1\&.0);
49 complex rz = creci(z);
50 complex z2 = cmul(z, z);
51 complex p = cdiv(one, z2);
52 complex q = csqrt(csub(one, p));
53 complex w = cmul(j, clog(cadd(cmul(i, q), rz)));
54 return w;
55 }
.fi
.SS "\fBcomplex\fP casech (\fBcomplex\fP z)"
.PP
Inverse hyperbolic secant of complex numbers\&.
.PP
\fBVersion:\fP
.RS 4
1\&.1
.RE
.PP
\fBDate:\fP
.RS 4
15/03/03
.RE
.PP
Inverse hyperbolic secant expressed using complex logarithms:
.PP
.nf
asech(z) = log(sqrt(1 / (z * z) - 1) + 1/z)
.fi
.PP
.PP
.PP
.nf
.fi
.PP
More info is available at Wikipedia:
.br
https://wikipedia.org/wiki/Inverse_hyperbolic_function#Logarithmic_representation
.PP
Definition at line 45 of file casech\&.c\&.
.PP
.nf
46 {
47 complex one = cpack(1\&.0, 0\&.0);
48 complex a = creci(cmul(z, z));
49 complex b = csqrt(csub(a, one));
50 complex c = cadd(b, creci(z));
51 complex w = clog(c);
52 return w;
53 }
.fi
.SS "\fBcomplex\fP casin (\fBcomplex\fP z)"
.PP
Inverse sine of complex number\&.
.PP
\fBVersion:\fP
.RS 4
1\&.1
.RE
.PP
\fBDate:\fP
.RS 4
14/10/01
.RE
.PP
Inverse sine expressed using complex logarithms:
.PP
.nf
arcsin z = -i * log(iz + sqrt(1 - z*z))
.fi
.PP
More info is available at Wikipedia:
.br
https://wikipedia.org/wiki/Inverse_trigonometric_functions#Logarithmic_forms
.PP
Definition at line 44 of file casin\&.c\&.
.PP
.nf
45 {
46 complex one = cpack(1\&.0, 0\&.0);
47 complex i = cpack(0\&.0, 1\&.0);
48 complex j = cpack(0\&.0, -1\&.0);
49 complex iz = cmul(i, z);
50 complex z2 = cmul(z, z);
51 complex p = csqrt(csub(one, z2));
52 complex q = clog(cadd(iz, p));
53 complex w = cmul(j, q);
54 return w;
55 }
.fi
.SS "\fBcomplex\fP casinh (\fBcomplex\fP z)"
.PP
Inverse hyperbolic sine of complex number\&.
.PP
\fBVersion:\fP
.RS 4
1\&.0
.RE
.PP
\fBDate:\fP
.RS 4
14/09/15
.RE
.PP
Inverse hyperbolic sine expressed using complex logarithms:
.PP
.nf
asinh(z) = log(z + sqrt(z*z + 1))
.fi
.PP
.PP
.PP
.nf
With branch cuts: -i INF to -i and i to i INF
.fi
.PP
.PP
.PP
.nf
Domain: -INF to INF
Range: -INF to INF
.fi
.PP
More info is available at Wikipedia:
.br
https://wikipedia.org/wiki/Inverse_hyperbolic_function#Logarithmic_representation
.PP
Definition at line 49 of file casinh\&.c\&.
.PP
.nf
50 {
51 complex one = cpack(1\&.0, 0\&.0);
52 complex a = cadd(cmul(z, z), one);
53 complex b = cadd(z, csqrt(a));
54 complex w = clog(b);
55 return w;
56 }
.fi
.SS "\fBcomplex\fP catan (\fBcomplex\fP z)"
.PP
Inverse tangent of complex number\&.
.PP
\fBVersion:\fP
.RS 4
1\&.1
.RE
.PP
\fBDate:\fP
.RS 4
14/10/01
.RE
.PP
Inverse tangent expressed using complex logarithms:
.PP
.nf
atan(z) = i/2 * (log(1 - i * z) - log(1 + i * z))
.fi
.PP
More info is available at Wikipedia:
.br
https://wikipedia.org/wiki/Inverse_trigonometric_functions#Logarithmic_forms
.PP
Definition at line 44 of file catan\&.c\&.
.PP
.nf
45 {
46 complex one = cpack(1\&.0, 0\&.0);
47 complex two = cpack(2\&.0, 0\&.0);
48 complex i = cpack(0\&.0, 1\&.0);
49 complex iz = cmul(i, z);
50 complex p = clog(csub(one, iz));
51 complex q = clog(cadd(one, iz));
52 complex w = cmul(cdiv(i, two), csub(p, q));
53 return w;
54 }
.fi
.SS "\fBcomplex\fP catanh (\fBcomplex\fP z)"
.PP
Inverse hyperbolic tangent of complex number\&.
.PP
\fBVersion:\fP
.RS 4
1\&.0
.RE
.PP
\fBDate:\fP
.RS 4
14/09/15
.RE
.PP
Inverse hyperbolic tangent expressed using complex logarithms:
.PP
.nf
atanh(z) = 1/2 * ((log(1 + z) - log(1 - z))
.fi
.PP
More info is available at Wikipedia:
.br
https://wikipedia.org/wiki/Inverse_hyperbolic_function#Logarithmic_representation
.PP
Definition at line 44 of file catanh\&.c\&.
.PP
.nf
45 {
46 complex half = cpack(0\&.5, 0\&.0);
47 complex one = cpack(1\&.0, 0\&.0);
48 complex a = clog(cadd(one, z));
49 complex b = clog(csub(one, z));
50 complex c = csub(a, b);
51 complex w = cmul(half, c);
52 return w;
53 }
.fi
.SS "\fBcomplex\fP ccbrt (\fBcomplex\fP z)"
.PP
Cube root of complex number\&.
.PP
.nf
cbrt z = exp(1/3 * log(z))
.fi
.PP
More info is available at Wikipedia:
.br
https://wikipedia.org/wiki/Cube_root
.PP
Definition at line 41 of file ccbrt\&.c\&.
.PP
.nf
42 {
43 complex onethird = cpack(1\&.0 / 3\&.0, 0\&.0);
44 complex a = cmul(onethird, clog(z));
45 complex w = cexp(a);
46 return w;
47 }
.fi
.SS "\fBcomplex\fP cceil (\fBcomplex\fP z)"
.PP
Ceiling value of complex number\&.
.PP
Definition at line 107 of file prim\&.c\&.
.PP
.nf
108 {
109 complex w;
110 w = cpack(ceil(creal(z)), ceil(cimag(z)));
111 return w;
112 }
.fi
.SS "\fBcomplex\fP ccos (\fBcomplex\fP z)"
.PP
Cosine of complex number\&.
.PP
\fBVersion:\fP
.RS 4
1\&.1
.RE
.PP
\fBDate:\fP
.RS 4
2007/08/20
.RE
.PP
.PP
.nf
a+bi
real = cos(a) * cosh(b)
imag = -sin(a) * sinh(b)
.fi
.PP
.PP
Definition at line 47 of file ccos\&.c\&.
.PP
.nf
48 {
49 complex w;
50 double a, b;
51 double ch, sh;
52
53 a = creal(z);
54 b = cimag(z);
55 cchsh(b, &ch, &sh);
56 w = cpack((cos(a) * ch), (-sin(a) * sh));
57
58 return w;
59 }
.fi
.SS "\fBcomplex\fP ccosh (\fBcomplex\fP z)"
.PP
Hyperbolic cosine of a complex number\&.
.PP
\fBVersion:\fP
.RS 4
1\&.1
.RE
.PP
\fBDate:\fP
.RS 4
2007/08/20
.RE
.PP
.nf
a+bi
real = cosh(a) * cos(b)
imag = sinh(a) * sin(b)
.fi
.PP
Definition at line 50 of file ccosh\&.c\&.
.PP
.nf
51 {
52 complex w;
53 double a, b;
54 double ch, sh;
55
56 a = creal(z);
57 b = cimag(z);
58 cchsh(a, &ch, &sh);
59 w = cpack(cos(b) * ch, sin(b) * sh);
60
61 return w;
62 }
.fi
.SS "\fBcomplex\fP ccot (\fBcomplex\fP z)"
.PP
Cotangent of a complex number\&. Calculated as in Open Office:
.PP
.nf
a+bi
sin(2\&.0 * a)
real = ------------------------------
cosh(2\&.0 * b) - cos(2\&.0 * a)
.fi
.PP
.nf
-sinh(2\&.0 * b)
imag = ------------------------------
cosh(2\&.0 * b) - cos(2\&.0 * a)
.fi
.PP
https://wiki.openoffice.org/wiki/Documentation/How_Tos/Calc:_IMCOT_function
.PP
Definition at line 48 of file ccot\&.c\&.
.PP
.nf
49 {
50 complex w;
51 double a, b;
52 double d;
53
54 a = creal(z);
55 b = cimag(z);
56 d = cosh(2\&.0 * b) - cos(2\&.0 * a);
57
58 if (d == 0\&.0)
59 {
60 w = cpack((double)INFP, (double)INFP);
61 }
62 else
63 {
64 w = cpack((sin(2\&.0 * a) / d), (-sinh(2\&.0 * b) / d));
65 }
66
67 return w;
68 }
.fi
.SS "\fBcomplex\fP ccoth (\fBcomplex\fP z)"
.PP
Hyperbolic cotangent of a complex number\&.
.PP
.nf
acoth(z) = 0\&.5 * (log(1 + 1/z) - log(1 - 1/z))
.fi
.PP
or
.PP
.nf
a+bi
sinh(2\&.0 * a)
real = ------------------------------
cosh(2\&.0 * a) - cos(2\&.0 * b)
.PP
.nf
-sin(2.0 * b)
.fi
.PP
imag = ------------------------------
cosh(2\&.0 * a) - cos(2\&.0 * b)
.fi
.PP
.PP
Definition at line 50 of file ccoth\&.c\&.
.PP
.nf
51 {
52 complex w;
53 double a, b;
54 double d;
55
56 a = creal(z);
57 b = cimag(z);
58 d = cosh(2\&.0 * a) - cos(2\&.0 * b);
59 w = cpack(sinh(2\&.0 * a) / d, -sin(2\&.0 * b) / d);
60
61 return w;
62 }
.fi
.SS "\fBcomplex\fP ccsc (\fBcomplex\fP z)"
.PP
Cosecant of a complex number\&. Calculated as in Open Office:
.PP
.nf
a+bi
2\&.0 * sin(a) * cosh(b)
real = ------------------------------
cosh(2\&.0 * b) - cos(2\&.0 * a)
.fi
.PP
.PP
.PP
.nf
-2\&.0 * cos(a) * sinh(b)
imag = ------------------------------
cosh(2\&.0 * b) - cos(2\&.0 * a)
.fi
.PP
https://wiki.openoffice.org/wiki/Documentation/How_Tos/Calc:_IMCSC_function
.PP
Definition at line 48 of file ccsc\&.c\&.
.PP
.nf
49 {
50 complex w;
51 double a, b;
52 double d;
53
54 a = creal(z);
55 b = cimag(z);
56 d = cosh(2\&.0 * b) - cos(2\&.0 * a);
57
58 if (d == 0\&.0)
59 {
60 w = cpack((double)INFP, (double)INFP);
61 }
62 else
63 {
64 w = cpack((2\&.0 * sin(a) * cosh(b) / d), (-2\&.0 * cos(a) * sinh(b) / d));
65 }
66
67 return w;
68 }
.fi
.SS "\fBcomplex\fP ccsch (\fBcomplex\fP z)"
.PP
Hyperbolic secant of a complex number\&. Calculated as in Open Office:
.br
https://wiki.openoffice.org/wiki/Documentation/How_Tos/Calc:_IMCSCH_function
.PP
.nf
a+bi
2\&.0 * sinh(a) * cos(b)
real = ------------------------------
cosh(2\&.0 * a) - cos(2\&.0 * b)
.fi
.PP
.PP
.PP
.nf
-2\&.0 * cosh(2\&.0 * a) * sin(b)
imag = ------------------------------
cosh(2\&.0 * a) - cos(2\&.0 * b)
.fi
Definition at line 48 of file ccsch\&.c\&.
.PP
.nf
49 {
50 complex w;
51 double a, b;
52 double d;
53
54 a = creal(z);
55 b = cimag(z);
56 d = cosh(2\&.0 * a) - cos(2\&.0 * b);
57 w = cpack((2\&.0 * sinh(a) * cos(b) / d), (-2\&.0 * cosh(a) * sin(b) / d));
58
59 return w;
60 }
.fi
.SS "\fBcomplex\fP cdiv (\fBcomplex\fP a, \fBcomplex\fP z)"
.PP
Division of two complex numbers\&.
.PP
Definition at line 171 of file prim\&.c\&.
.PP
.nf
172 {
173 complex w;
174 double a, b, c, d;
175 double q, v, x;
176
177 a = creal(y);
178 b = cimag(y);
179 c = creal(z);
180 d = cimag(z);
181
182 q = c * c + d * d;
183 v = a * c + b * d;
184 x = b * c - a * d;
185
186 w = cpack(v / q, x / q);
187 return w;
188 }
.fi
.SS "\fBcomplex\fP cexp (\fBcomplex\fP z)"
.PP
Returns e to the power of a complex number\&.
.PP
\fBVersion:\fP
.RS 4
1\&.1
.RE
.PP
\fBDate:\fP
.RS 4
2007/08/20
.RE
.PP
.PP
Definition at line 45 of file cexp\&.c\&.
.PP
.nf
46 {
47 complex w;
48 double r, x, y;
49 x = creal(z);
50 y = cimag(z);
51 r = exp(x);
52 w = cpack(r * cos(y), r * sin(y));
53 return w;
54 }
.fi
.SS "\fBcomplex\fP cfloor (\fBcomplex\fP z)"
.PP
Floor value of complex number\&.
.PP
Definition at line 96 of file prim\&.c\&.
.PP
.nf
97 {
98 complex w;
99 w = cpack(floor(creal(z)), floor(cimag(z)));
100 return w;
101 }
.fi
.SS "double cimag (\fBcomplex\fP z)"
.PP
Imaginary part of complex number\&.
.PP
Definition at line 48 of file prim\&.c\&.
.PP
.nf
49 {
50 return (IMAG_PART(z));
51 }
.fi
.SS "\fBcomplex\fP clog (\fBcomplex\fP z)"
.PP
Natural logarithm of a complex number\&.
.PP
\fBVersion:\fP
.RS 4
1\&.1
.RE
.PP
\fBDate:\fP
.RS 4
2007/08/20
.RE
.PP
.PP
Definition at line 45 of file clog\&.c\&.
.PP
.nf
46 {
47 complex w;
48 double p, q;
49 p = log(cabs(z));
50 q = atan2(cimag(z), creal(z));
51 w = cpack(p, q);
52 return w;
53 }
.fi
.SS "\fBcomplex\fP clog10 (\fBcomplex\fP z)"
.PP
Base 10 logarithmic value of complex number\&.
.PP
.nf
log z = log(z) / log(10)
.fi
.PP
More info is available at Wikipedia:
.br
https://wikipedia.org/wiki/Complex_logarithm
.PP
Definition at line 41 of file clog10\&.c\&.
.PP
.nf
42 {
43 complex teen = cpack(10\&.0, 0\&.0);
44 complex w = cdiv(clog(z), clog(teen));
45 return w;
46 }
.fi
.SS "\fBcomplex\fP clogb (\fBcomplex\fP z)"
.PP
Base 2 logarithmic value of complex number\&.
.PP
.nf
lb z = log(z) / log(2)
.fi
.PP
More info is available at Wikipedia:
.br
https://wikipedia.org/wiki/Complex_logarithm
.PP
Definition at line 41 of file clogb\&.c\&.
.PP
.nf
42 {
43 complex two = cpack(2\&.0, 0\&.0);
44 complex w = cdiv(clog(z), clog(two));
45 return w;
46 }
.fi
.SS "\fBcomplex\fP cmul (\fBcomplex\fP a, \fBcomplex\fP z)"
.PP
Multiplication of two complex numbers\&.
.PP
Definition at line 151 of file prim\&.c\&.
.PP
.nf
152 {
153 complex w;
154 double a, b, c, d;
155
156 // (a+bi)(c+di)
157 a = creal(y);
158 b = cimag(y);
159 c = creal(z);
160 d = cimag(z);
161
162 // (ac -bd) + (ad + bc)i
163 w = cpack(a * c - b * d, a * d + b * c);
164 return w;
165 }
.fi
.SS "\fBcomplex\fP conj (\fBcomplex\fP z)"
.PP
Definition at line 62 of file prim\&.c\&.
.PP
.nf
63 {
64 IMAG_PART(z) = -IMAG_PART(z);
65 return cpack(REAL_PART(z), IMAG_PART(z));
66 }
.fi
.SS "\fBcomplex\fP cpack (double x, double y)"
.PP
Pack two real numbers into a complex number\&.
.PP
Definition at line 72 of file prim\&.c\&.
.PP
.nf
73 {
74 complex z;
75
76 REAL_PART(z) = x;
77 IMAG_PART(z) = y;
78 return (z);
79 }
.fi
.SS "\fBcomplex\fP cpow (\fBcomplex\fP a, \fBcomplex\fP z)"
.PP
Complex number raised to a power\&.
.PP
\fBVersion:\fP
.RS 4
1\&.1
.RE
.PP
\fBDate:\fP
.RS 4
2007/08/20
.RE
.PP
.PP
Definition at line 45 of file cpow\&.c\&.
.PP
.nf
46 {
47 complex w;
48 double x, y, r, theta, absa, arga;
49
50 x = creal(z);
51 y = cimag(z);
52 absa = cabs(a);
53 if (absa == 0\&.0)
54 {
55 return cpack(0\&.0, + 0\&.0);
56 }
57 arga = atan2(cimag(a), creal(a));
58
59 r = pow(absa, x);
60 theta = x * arga;
61 if (y != 0\&.0)
62 {
63 r = r * exp(-y * arga);
64 theta = theta + y * log(absa);
65 }
66
67 w = cpack(r * cos(theta), r * sin(theta));
68 return w;
69 }
.fi
.SS "double creal (\fBcomplex\fP z)"
.PP
Real part of complex number\&.
.PP
Definition at line 39 of file prim\&.c\&.
.PP
.nf
40 {
41 return (REAL_PART(z));
42 }
.fi
.SS "\fBcomplex\fP creci (\fBcomplex\fP z)"
.PP
Reciprocal value of complex number\&.
.PP
Definition at line 194 of file prim\&.c\&.
.PP
.nf
195 {
196 complex w;
197 double q, a, b;
198
199 a = creal(z);
200 b = cimag(conj(z));
201 q = a * a + b * b;
202 w = cpack(a / q, b / q);
203
204 return w;
205 }
.fi
.SS "\fBcomplex\fP cround (\fBcomplex\fP z)"
.PP
Division of two complex numbers\&.
.PP
Definition at line 118 of file prim\&.c\&.
.PP
.nf
119 {
120 complex w;
121 w = cpack(round(creal(z)), round(cimag(z)));
122 return w;
123 }
.fi
.SS "\fBcomplex\fP csec (\fBcomplex\fP z)"
.PP
Secant of a complex number\&. Calculated as in Open Office:
.br
https://wiki.openoffice.org/wiki/Documentation/How_Tos/Calc:_IMSEC_function
.PP
.nf
a+bi
2\&.0 * cos(a) * cosh(b)
real = ------------------------------
cosh(2\&.0 * b) + cos(2\&.0 * a)
.fi
.PP
.PP
.PP
.nf
2\&.0 * sin(a) * sinh(b)
imag = ------------------------------
cosh(2\&.0 * b) + cos(2\&.0 * a)
.fi
.PP
.PP
Definition at line 48 of file csec\&.c\&.
.PP
.nf
49 {
50 complex w;
51 double a, b;
52 double d;
53
54 a = creal(z);
55 b = cimag(z);
56 d = cosh(2\&.0 * b) + cos(2\&.0 * a);
57
58 if (d == 0\&.0)
59 {
60 w = cpack((double)INFP, (double)INFP);
61 }
62 else
63 {
64 w = cpack((2\&.0 * cos(a) * cosh(b) / d), (2\&.0 * sin(a) * sinh(b) / d));
65 }
66
67 return w;
68 }
.fi
.SS "\fBcomplex\fP csech (\fBcomplex\fP z)"
.PP
Hyperbolic secant of a complex number\&. Calculated as in Open Office:
.br
https://wiki.openoffice.org/wiki/Documentation/How_Tos/Calc:_IMSECH_function
.PP
.nf
a+bi
2\&.0 * cosh(a) * cos(b)
real = ------------------------------
cosh(2\&.0 * a) + cos(2\&.0 * b)
.fi
.PP
.PP
.PP
.nf
-2\&.0 * sinh(2\&.0 * a) * sin(b)
imag = ------------------------------
cosh(2\&.0 * a) + cos(2\&.0 * b)
.fi
.PP
.PP
Definition at line 48 of file csech\&.c\&.
.PP
.nf
49 {
50 complex w;
51 double a, b;
52 double d;
53
54 a = creal(z);
55 b = cimag(z);
56 d = cosh(2\&.0 * a) + cos(2\&.0 * b);
57 w = cpack((2\&.0 * cosh(a) * cos(b) / d), (-2\&.0 * sinh(a) * sin(b) / d));
58
59 return w;
60 }
.fi
.SS "double csgn (\fBcomplex\fP z)"
.PP
Complex signum\&. More info is available at Wikipedia:
.br
https://wikipedia.org/wiki/Sign_function#Complex_signum
.PP
Definition at line 39 of file csgn\&.c\&.
.PP
.nf
40 {
41 double a = creal(z);
42
43 if (a > 0\&.0)
44 {
45 return 1\&.0;
46 }
47 else if (a < 0\&.0)
48 {
49 return -1\&.0;
50 }
51 else
52 {
53 double b = cimag(z);
54 return b > 0\&.0 ? 1\&.0 : b < 0\&.0 ? -1\&.0 : 0\&.0;
55 }
56 }
.fi
.SS "\fBcomplex\fP csin (\fBcomplex\fP z)"
.PP
Sine of a complex number\&.
.PP
\fBVersion:\fP
.RS 4
1\&.1
.RE
.PP
\fBDate:\fP
.RS 4
2007/08/20
.RE
.PP
Calculated according to description at wikipedia:
.br
https://wikipedia.org/wiki/Sine#Sine_with_a_complex_argument
.PP
.nf
a+bi
real = sin(a) * cosh(b)
imag = cos(a) * sinh(b)
.fi
.PP
.PP
Definition at line 52 of file csin\&.c\&.
.PP
.nf
53 {
54 complex w;
55 double a, b;
56 double ch, sh;
57
58 a = creal(z);
59 b = cimag(z);
60 cchsh(b, &ch, &sh);
61 w = cpack((sin(a) * ch), (cos(a) * sh));
62
63 return w;
64 }
.fi
.SS "\fBcomplex\fP csinh (\fBcomplex\fP z)"
.PP
Hyperbolic sine of a complex number\&.
.PP
\fBVersion:\fP
.RS 4
1\&.1
.RE
.PP
\fBDate:\fP
.RS 4
2007/08/20
.RE
.PP
Calculated as in Open Office:
.br
https://wiki.openoffice.org/wiki/Documentation/How_Tos/Calc:_IMSINH_function
.PP
.nf
a+bi
real = sinh(a) * cos(b)
imag = cosh(a) * sin(b)
.fi
.PP
.PP
Definition at line 52 of file csinh\&.c\&.
.PP
.nf
53 {
54 complex w;
55 double a, b;
56 double ch, sh;
57
58 a = creal(z);
59 b = cimag(z);
60 cchsh(a, &ch, &sh);
61 w = cpack(cos(b) * sh, sin(b) * ch);
62
63 return w;
64 }
.fi
.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 45 of file csqrt\&.c\&.
.PP
.nf
46 {
47 complex w;
48 double x, y, r, t, scale;
49
50 x = creal(z);
51 y = cimag(z);
52
53 if (y == 0\&.0)
54 {
55 if (x == 0\&.0)
56 {
57 w = cpack(0\&.0, y);
58 }
59 else
60 {
61 r = fabs(x);
62 r = sqrt(r);
63 if (x < 0\&.0)
64 {
65 w = cpack(0\&.0, r);
66 }
67 else
68 {
69 w = cpack(r, y);
70 }
71 }
72 return w;
73 }
74 if (x == 0\&.0)
75 {
76 r = fabs(y);
77 r = sqrt(0\&.5 * r);
78 if (y > 0)
79 w = cpack(r, r);
80 else
81 w = cpack(r, -r);
82 return w;
83 }
84 /* Rescale to avoid internal overflow or underflow\&. */
85 if ((fabs(x) > 4\&.0) || (fabs(y) > 4\&.0))
86 {
87 x *= 0\&.25;
88 y *= 0\&.25;
89 scale = 2\&.0;
90 }
91 else
92 {
93 #if 1
94 x *= 1\&.8014398509481984e16; /* 2^54 */
95 y *= 1\&.8014398509481984e16;
96 scale = 7\&.450580596923828125e-9; /* 2^-27 */
97 #else
98 x *= 4\&.0;
99 y *= 4\&.0;
100 scale = 0\&.5;
101 #endif
102 }
103 w = cpack(x, y);
104 r = cabs(w);
105 if (x > 0)
106 {
107 t = sqrt(0\&.5 * r + 0\&.5 * x);
108 r = scale * fabs((0\&.5 * y) / t);
109 t *= scale;
110 }
111 else
112 {
113 r = sqrt(0\&.5 * r - 0\&.5 * x);
114 t = scale * fabs((0\&.5 * y) / r);
115 r *= scale;
116 }
117 if (y < 0)
118 w = cpack(t, -r);
119 else
120 w = cpack(t, r);
121 return w;
122 }
.fi
.SS "\fBcomplex\fP csub (\fBcomplex\fP a, \fBcomplex\fP z)"
.PP
Subtraction of two complex numbers\&.
.PP
Definition at line 140 of file prim\&.c\&.
.PP
.nf
141 {
142 complex w;
143 w = cpack(creal(y) - creal(z), cimag(y) - cimag(z));
144 return w;
145 }
.fi
.SS "\fBcomplex\fP ctan (\fBcomplex\fP z)"
.PP
Tangent of a complex number\&.
.PP
\fBVersion:\fP
.RS 4
1\&.1
.RE
.PP
\fBDate:\fP
.RS 4
2007/08/20
.RE
.PP
Calculated as in Open Office:
.br
https://wiki.openoffice.org/wiki/Documentation/How_Tos/Calc:_IMTAN_function
.PP
.nf
a+bi
sin(2\&.0 * a)
real = ------------------------------
cos(2\&.0 * a) + cosh(2\&.0 * b)
.PP
.nf
sinh(2.0 * b)
.fi
.PP
imag = ------------------------------
cos(2\&.0 * a) + cosh(2\&.0 * b)
.fi
.PP
.PP
Definition at line 57 of file ctan\&.c\&.
.PP
.nf
58 {
59 complex w;
60 double a, b;
61 double d;
62
63 a = creal(z);
64 b = cimag(z);
65 d = cos(2\&.0 * a) + cosh(2\&.0 * b);
66
67 if (d == 0\&.0)
68 {
69 w = cpack((double)INFP, (double)INFP);
70 }
71 else
72 {
73 w = cpack((sin(2\&.0 * a) / d), (sinh(2\&.0 * b) / d));
74 }
75
76 return w;
77 }
.fi
.SS "\fBcomplex\fP ctanh (\fBcomplex\fP z)"
.PP
Hyperbolic tangent of a complex number\&.
.PP
\fBVersion:\fP
.RS 4
1\&.1
.RE
.PP
\fBDate:\fP
.RS 4
2007/08/20
.RE
.PP
.PP
.nf
a+bi
sinh(2\&.0 * a)
real = ------------------------------
cosh(2\&.0 * a) + cos(2\&.0 * b)
.PP
.nf
sin(2.0 * b)
.fi
.PP
imag = ------------------------------
cosh(2\&.0 * a) + cos(2\&.0 * b)
.fi
.PP
.PP
Definition at line 55 of file ctanh\&.c\&.
.PP
.nf
56 {
57 complex w;
58 double a, b;
59 double d;
60
61 a = creal(z);
62 b = cimag(z);
63 d = cosh(2\&.0 * a) + cos(2\&.0 * b);
64 w = cpack((sinh(2\&.0 * a) / d), (sin(2\&.0 * b) / d));
65
66 return w;
67 }
.fi
.SS "\fBcomplex\fP ctrunc (\fBcomplex\fP z)"
.PP
Truncated value of complex number\&.
.PP
Definition at line 85 of file prim\&.c\&.
.PP
.nf
86 {
87 complex w;
88 w = cpack(trunc(creal(z)), trunc(cimag(z)));
89 return w;
90 }
.fi
.SH HOMEPAGE
https://amath.innolan.net/
.SH AUTHORS
.PP
Written by Carsten Sonne Larsen <cs@innolan.net>. Some code in the
library is derived from software written by Stephen L. Moshier.
.SH COPYRIGHT
Copyright (c) 2014-2021 Carsten Sonne Larsen <cs@innolan.net>
.br
Copyright (c) 2007 The NetBSD Foundation, Inc.
.SH "See also"
amath(1), amathc(3), amathr(3)