|
NAMEmathi.h - Complex numbers math librarySYNOPSISData Structuresunion complex Functionsdouble csgn (complex z) Complex signum. double cabs (complex z) Absolute value of complex number. double creal (complex z) Real part of complex number. double cimag (complex z) Imaginary part of complex number. complex cpack (double x, double y) Pack two real numbers into a complex number. complex cadd (complex a, complex z) Addition of two complex numbers. complex csub (complex a, complex z) Subtraction of two complex numbers. complex cmul (complex a, complex z) Multiplication of two complex numbers. complex cdiv (complex a, complex z) Division of two complex numbers. complex cpow (complex x, complex z) Complex number raised to a power. complex cceil (complex z) Ceiling value of complex number. complex cfloor (complex z) Floor value of complex number. complex ctrunc (complex z) Truncated value of complex number. complex cround (complex z) Division of two complex numbers. complex creci (complex z) Reciprocal value of complex number. complex conj (complex z) complex cexp (complex z) Returns e to the power of a complex number. complex csqrt (complex z) Square root of complex number. complex ccbrt (complex z) Cube root of complex number. complex clog (complex z) Natural logarithm of a complex number. complex clogb (complex z) Base 2 logarithmic value of complex number. complex clog10 (complex z) Base 10 logarithmic value of complex number. complex ccos (complex z) Cosine of complex number. complex csin (complex z) Sine of a complex number. complex ctan (complex z) Tangent of a complex number. complex csec (complex z) Secant of a complex number. complex ccsc (complex z) Cosecant of a complex number. complex ccot (complex z) Cotangent of a complex number. complex cacos (complex z) Inverse cosine of complex number. complex casin (complex z) Inverse sine of complex number. complex catan (complex z) Inverse tangent of complex number. complex casec (complex z) Inverse secant expressed using complex logarithms: complex cacsc (complex z) Inverse cosecant of complex number. complex cacot (complex z) Inverse cotangent of complex number. complex ccosh (complex z) Hyperbolic cosine of a complex number. complex csinh (complex z) Hyperbolic sine of a complex number. complex ctanh (complex z) Hyperbolic tangent of a complex number. complex csech (complex z) Hyperbolic secant of a complex number. complex ccsch (complex z) Hyperbolic secant of a complex number. complex ccoth (complex z) Hyperbolic cotangent of a complex number. complex cacosh (complex z) Inverse hyperbolic cosine of complex number. complex casinh (complex z) Inverse hyperbolic sine of complex number. complex catanh (complex z) Inverse hyperbolic tangent of complex number. complex casech (complex z) Inverse hyperbolic secant of complex numbers. complex cacsch (complex z) Inverse hyperbolic cosecant of complex number. complex cacoth (complex z) Inverse hyperbolic cotangent of complex number. Detailed DescriptionFunctions for handling complex numbers. Mostly as specified in IEEE Std 1003.1, 2013 Edition:http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/complex.h.html Definition in file mathi.h. Function Documentationdouble cabs (complex z)Absolute value of complex number.Definition at line 57 of file prim.c. 58 { 59 return hypot(creal(z), cimag(z)); 60 } complex cacos (complex z)Inverse cosine of complex number.Version: 1.0
Date: 14/09/15
Inverse cosine expressed using complex logarithms: arccos z = -i * log(z + i * sqrt(1 - z * z)) More info is available at Wikipedia: https://wikipedia.org/wiki/Inverse_trigonometric_functions#Logarithmic_forms Definition at line 44 of file cacos.c. 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 } complex cacosh (complex z)Inverse hyperbolic cosine of complex number.Version: 1.1
Date: 15/03/03
Inverse hyperbolic cosine expressed using complex logarithms: acosh(z) = log(z + sqrt(z*z - 1)) More info is available at Wikipedia: https://wikipedia.org/wiki/Inverse_hyperbolic_function#Logarithmic_representation Definition at line 44 of file cacosh.c. 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 } complex cacot (complex z)Inverse cotangent of complex number.Version: 1.1
Date: 14/10/01
Inverse cotangent expressed using complex logarithms: arccot z = i/2 * (log(1 - i/z) - log(1 + i/z)) More info is available at Wikipedia: https://wikipedia.org/wiki/Inverse_trigonometric_functions#Logarithmic_forms Definition at line 44 of file cacot.c. 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 } complex cacoth (complex z)Inverse hyperbolic cotangent of complex number.Version: 1.0
Date: 14/09/15
Inverse hyperbolic cotangent expressed using complex logarithms: acoth(z) = 1/2 * ((log(z + 1) - log(z - 1)) More info is available at Wikipedia: https://wikipedia.org/wiki/Inverse_hyperbolic_function#Logarithmic_representation Definition at line 44 of file cacoth.c. 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 } complex cacsc (complex z)Inverse cosecant of complex number.Version: 1.1
Date: 14/10/01
Inverse cosecant expressed using complex logarithms: arccsc z = -i * log(sqr(1 - 1/(z*z)) + i/z) More info is available at Wikipedia: https://wikipedia.org/wiki/Inverse_trigonometric_functions#Logarithmic_forms Definition at line 44 of file cacsc.c. 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 } complex cacsch (complex z)Inverse hyperbolic cosecant of complex number.Version: 1.0
Date: 14/09/15
Inverse hyperbolic cosecant expressed using complex logarithms: acsch(z) = log(sqrt(1 + 1 / (z * z)) + 1/z) More info is available at Wikipedia: https://wikipedia.org/wiki/Inverse_hyperbolic_function#Logarithmic_representation Definition at line 44 of file cacsch.c. 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 } complex cadd (complex a, complex z)Addition of two complex numbers.Definition at line 129 of file prim.c. 130 { 131 complex w; 132 w = cpack(creal(y) + creal(z), cimag(y) + cimag(z)); 133 return w; 134 } complex casec (complex z)Inverse secant expressed using complex logarithms:Version: 1.1
Date: 14/10/01
Inverse secant expressed using complex logarithms: arcsec z = -i * log(i * sqr(1 - 1/(z*z)) + 1/z) More info is available at Wikipedia: https://wikipedia.org/wiki/Inverse_trigonometric_functions#Logarithmic_forms Definition at line 44 of file casec.c. 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 } complex casech (complex z)Inverse hyperbolic secant of complex numbers.Version: 1.1
Date: 15/03/03
Inverse hyperbolic secant expressed using complex logarithms: asech(z) = log(sqrt(1 / (z * z) - 1) + 1/z) More info is available at Wikipedia: https://wikipedia.org/wiki/Inverse_hyperbolic_function#Logarithmic_representation Definition at line 45 of file casech.c. 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 } complex casin (complex z)Inverse sine of complex number.Version: 1.1
Date: 14/10/01
Inverse sine expressed using complex logarithms: arcsin z = -i * log(iz + sqrt(1 - z*z)) More info is available at Wikipedia: https://wikipedia.org/wiki/Inverse_trigonometric_functions#Logarithmic_forms Definition at line 44 of file casin.c. 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 } complex casinh (complex z)Inverse hyperbolic sine of complex number.Version: 1.0
Date: 14/09/15
Inverse hyperbolic sine expressed using complex logarithms: asinh(z) = log(z + sqrt(z*z + 1)) With branch cuts: -i INF to -i and i to i INF Domain: -INF to INF Range: -INF to INF More info is available at Wikipedia: https://wikipedia.org/wiki/Inverse_hyperbolic_function#Logarithmic_representation Definition at line 49 of file casinh.c. 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 } complex catan (complex z)Inverse tangent of complex number.Version: 1.1
Date: 14/10/01
Inverse tangent expressed using complex logarithms: atan(z) = i/2 * (log(1 - i * z) - log(1 + i * z)) More info is available at Wikipedia: https://wikipedia.org/wiki/Inverse_trigonometric_functions#Logarithmic_forms Definition at line 44 of file catan.c. 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 } complex catanh (complex z)Inverse hyperbolic tangent of complex number.Version: 1.0
Date: 14/09/15
Inverse hyperbolic tangent expressed using complex logarithms: atanh(z) = 1/2 * ((log(1 + z) - log(1 - z)) More info is available at Wikipedia: https://wikipedia.org/wiki/Inverse_hyperbolic_function#Logarithmic_representation Definition at line 44 of file catanh.c. 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 } complex ccbrt (complex z)Cube root of complex number.cbrt z = exp(1/3 * log(z)) More info is available at Wikipedia: https://wikipedia.org/wiki/Cube_root Definition at line 41 of file ccbrt.c. 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 } complex cceil (complex z)Ceiling value of complex number.Definition at line 107 of file prim.c. 108 { 109 complex w; 110 w = cpack(ceil(creal(z)), ceil(cimag(z))); 111 return w; 112 } complex ccos (complex z)Cosine of complex number.Version: 1.1
Date: 2007/08/20
a+bi real = cos(a) * cosh(b) imag = -sin(a) * sinh(b) Definition at line 47 of file ccos.c. 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 } complex ccosh (complex z)Hyperbolic cosine of a complex number.Version: 1.1
Date: 2007/08/20
a+bi real = cosh(a) * cos(b) imag = sinh(a) * sin(b) Definition at line 50 of file ccosh.c. 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 } complex ccot (complex z)Cotangent of a complex number. Calculated as in Open Office:a+bi sin(2.0 * a) real = ------------------------------ cosh(2.0 * b) - cos(2.0 * a) -sinh(2.0 * b) imag = ------------------------------ cosh(2.0 * b) - cos(2.0 * a) https://wiki.openoffice.org/wiki/Documentation/How_Tos/Calc:_IMCOT_function Definition at line 48 of file ccot.c. 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 } complex ccoth (complex z)Hyperbolic cotangent of a complex number.acoth(z) = 0.5 * (log(1 + 1/z) - log(1 - 1/z)) or a+bi sinh(2.0 * a) real = ------------------------------ cosh(2.0 * a) - cos(2.0 * b)
imag = ------------------------------
cosh(2.0 * a) - cos(2.0 * b)
Definition at line 50 of file ccoth.c. 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 } complex ccsc (complex z)Cosecant of a complex number. Calculated as in Open Office:a+bi 2.0 * sin(a) * cosh(b) real = ------------------------------ cosh(2.0 * b) - cos(2.0 * a) -2.0 * cos(a) * sinh(b) imag = ------------------------------ cosh(2.0 * b) - cos(2.0 * a) https://wiki.openoffice.org/wiki/Documentation/How_Tos/Calc:_IMCSC_function Definition at line 48 of file ccsc.c. 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 } complex ccsch (complex z)Hyperbolic secant of a complex number. Calculated as in Open Office:https://wiki.openoffice.org/wiki/Documentation/How_Tos/Calc:_IMCSCH_function a+bi 2.0 * sinh(a) * cos(b) real = ------------------------------ cosh(2.0 * a) - cos(2.0 * b) -2.0 * cosh(2.0 * a) * sin(b) imag = ------------------------------ cosh(2.0 * a) - cos(2.0 * b)Definition at line 48 of file ccsch.c. 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 } complex cdiv (complex a, complex z)Division of two complex numbers.Definition at line 171 of file prim.c. 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 } complex cexp (complex z)Returns e to the power of a complex number.Version: 1.1
Date: 2007/08/20
Definition at line 45 of file cexp.c. 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 } complex cfloor (complex z)Floor value of complex number.Definition at line 96 of file prim.c. 97 { 98 complex w; 99 w = cpack(floor(creal(z)), floor(cimag(z))); 100 return w; 101 } double cimag (complex z)Imaginary part of complex number.Definition at line 48 of file prim.c. 49 { 50 return (IMAG_PART(z)); 51 } complex clog (complex z)Natural logarithm of a complex number.Version: 1.1
Date: 2007/08/20
Definition at line 45 of file clog.c. 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 } complex clog10 (complex z)Base 10 logarithmic value of complex number.log z = log(z) / log(10) More info is available at Wikipedia: https://wikipedia.org/wiki/Complex_logarithm Definition at line 41 of file clog10.c. 42 { 43 complex teen = cpack(10.0, 0.0); 44 complex w = cdiv(clog(z), clog(teen)); 45 return w; 46 } complex clogb (complex z)Base 2 logarithmic value of complex number.lb z = log(z) / log(2) More info is available at Wikipedia: https://wikipedia.org/wiki/Complex_logarithm Definition at line 41 of file clogb.c. 42 { 43 complex two = cpack(2.0, 0.0); 44 complex w = cdiv(clog(z), clog(two)); 45 return w; 46 } complex cmul (complex a, complex z)Multiplication of two complex numbers.Definition at line 151 of file prim.c. 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 } complex conj (complex z)Definition at line 62 of file prim.c.63 { 64 IMAG_PART(z) = -IMAG_PART(z); 65 return cpack(REAL_PART(z), IMAG_PART(z)); 66 } complex cpack (double x, double y)Pack two real numbers into a complex number.Definition at line 72 of file prim.c. 73 { 74 complex z; 75 76 REAL_PART(z) = x; 77 IMAG_PART(z) = y; 78 return (z); 79 } complex cpow (complex a, complex z)Complex number raised to a power.Version: 1.1
Date: 2007/08/20
Definition at line 45 of file cpow.c. 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 } double creal (complex z)Real part of complex number.Definition at line 39 of file prim.c. 40 { 41 return (REAL_PART(z)); 42 } complex creci (complex z)Reciprocal value of complex number.Definition at line 194 of file prim.c. 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 } complex cround (complex z)Division of two complex numbers.Definition at line 118 of file prim.c. 119 { 120 complex w; 121 w = cpack(round(creal(z)), round(cimag(z))); 122 return w; 123 } complex csec (complex z)Secant of a complex number. Calculated as in Open Office: https://wiki.openoffice.org/wiki/Documentation/How_Tos/Calc:_IMSEC_functiona+bi 2.0 * cos(a) * cosh(b) real = ------------------------------ cosh(2.0 * b) + cos(2.0 * a) 2.0 * sin(a) * sinh(b) imag = ------------------------------ cosh(2.0 * b) + cos(2.0 * a) Definition at line 48 of file csec.c. 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 } complex csech (complex z)Hyperbolic secant of a complex number. Calculated as in Open Office: https://wiki.openoffice.org/wiki/Documentation/How_Tos/Calc:_IMSECH_functiona+bi 2.0 * cosh(a) * cos(b) real = ------------------------------ cosh(2.0 * a) + cos(2.0 * b) -2.0 * sinh(2.0 * a) * sin(b) imag = ------------------------------ cosh(2.0 * a) + cos(2.0 * b) Definition at line 48 of file csech.c. 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 } double csgn (complex z)Complex signum. More info is available at Wikipedia: https://wikipedia.org/wiki/Sign_function#Complex_signumDefinition at line 39 of file csgn.c. 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 } complex csin (complex z)Sine of a complex number.Version: 1.1
Date: 2007/08/20
Calculated according to description at wikipedia: https://wikipedia.org/wiki/Sine#Sine_with_a_complex_argument a+bi real = sin(a) * cosh(b) imag = cos(a) * sinh(b) Definition at line 52 of file csin.c. 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 } complex csinh (complex z)Hyperbolic sine of a complex number.Version: 1.1
Date: 2007/08/20
Calculated as in Open Office: https://wiki.openoffice.org/wiki/Documentation/How_Tos/Calc:_IMSINH_function a+bi real = sinh(a) * cos(b) imag = cosh(a) * sin(b) Definition at line 52 of file csinh.c. 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 } complex csqrt (complex z)Square root of complex number.Version: 1.1
Date: 2007/08/20
Definition at line 45 of file csqrt.c. 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 } complex csub (complex a, complex z)Subtraction of two complex numbers.Definition at line 140 of file prim.c. 141 { 142 complex w; 143 w = cpack(creal(y) - creal(z), cimag(y) - cimag(z)); 144 return w; 145 } complex ctan (complex z)Tangent of a complex number.Version: 1.1
Date: 2007/08/20
Calculated as in Open Office: https://wiki.openoffice.org/wiki/Documentation/How_Tos/Calc:_IMTAN_function a+bi sin(2.0 * a) real = ------------------------------ cos(2.0 * a) + cosh(2.0 * b)
imag = ------------------------------
cos(2.0 * a) + cosh(2.0 * b)
Definition at line 57 of file ctan.c. 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 } complex ctanh (complex z)Hyperbolic tangent of a complex number.Version: 1.1
Date: 2007/08/20
a+bi sinh(2.0 * a) real = ------------------------------ cosh(2.0 * a) + cos(2.0 * b)
imag = ------------------------------
cosh(2.0 * a) + cos(2.0 * b)
Definition at line 55 of file ctanh.c. 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 } complex ctrunc (complex z)Truncated value of complex number.Definition at line 85 of file prim.c. 86 { 87 complex w; 88 w = cpack(trunc(creal(z)), trunc(cimag(z))); 89 return w; 90 } HOMEPAGEhttps://amath.innolan.net/AUTHORSWritten by Carsten Sonne Larsen <cs@innolan.net>. Some code in the library is derived from software written by Stephen L. Moshier.COPYRIGHTCopyright (c) 2014-2018 Carsten Sonne Larsen <cs@innolan.net>Copyright (c) 2007 The NetBSD Foundation, Inc. See alsoamath(1), amathc(3), amathr(3)
Visit the GSP FreeBSD Man Page Interface. |