| Types and the imaginary constant | |||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||
| Manipulation | |||||||||||||||||||||||||||||||
| Power and exponential functions | |||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||
| Trigonometric functions | |||||||||||||||||||||||||||||||
| Hyperbolic functions | |||||||||||||||||||||||||||||||
Defined in header <complex.h> | ||
| (1) | (since C99) | |
| (2) | (since C99) | |
| (3) | (since C99) | |
Defined in header <tgmath.h> | ||
#define log( z ) | (4) | (since C99) |
z with branch cut along the negative real axis.z has typelongdoublecomplex,clogl is called. ifz has typedoublecomplex,clog is called, ifz has typefloatcomplex,clogf is called. Ifz is real or integer, then the macro invokes the corresponding real function (logf,log,logl). Ifz is imaginary, the corresponding complex number version is called.Contents |
| z | - | complex argument |
If no errors occur, the complex natural logarithm ofz is returned, in the range of a strip in the interval[−iπ, +iπ] along the imaginary axis and mathematically unbounded along the real axis.
Errors are reported consistent withmath_errhandling
If the implementation supports IEEE floating-point arithmetic,
z is-0+0i, the result is-∞+πi andFE_DIVBYZERO is raisedz is+0+0i, the result is-∞+0i andFE_DIVBYZERO is raisedz isx+∞i (for any finite x), the result is+∞+πi/2z isx+NaNi (for any finite x), the result isNaN+NaNi andFE_INVALID may be raisedz is-∞+yi (for any finite positive y), the result is+∞+πiz is+∞+yi (for any finite positive y), the result is+∞+0iz is-∞+∞i, the result is+∞+3πi/4z is+∞+∞i, the result is+∞+πi/4z is±∞+NaNi, the result is+∞+NaNiz isNaN+yi (for any finite y), the result isNaN+NaNi andFE_INVALID may be raisedz isNaN+∞i, the result is+∞+NaNiz isNaN+NaNi, the result isNaN+NaNiThe natural logarithm of a complex numberz with polar coordinate components(r,θ) equalsln r + i(θ+2nπ), with the principal valueln r + iθ
#include <stdio.h>#include <math.h>#include <complex.h> int main(void){doublecomplex z= clog(I);// r = 1, θ = pi/2printf("2*log(i) = %.1f%+fi\n",creal(2*z),cimag(2*z)); doublecomplex z2= clog(sqrt(2)/2+sqrt(2)/2*I);// r = 1, θ = pi/4printf("4*log(sqrt(2)/2+sqrt(2)i/2) = %.1f%+fi\n",creal(4*z2),cimag(4*z2)); doublecomplex z3= clog(-1);// r = 1, θ = piprintf("log(-1+0i) = %.1f%+fi\n",creal(z3),cimag(z3)); doublecomplex z4= clog(conj(-1));// or clog(CMPLX(-1, -0.0)) in C11printf("log(-1-0i) (the other side of the cut) = %.1f%+fi\n",creal(z4),cimag(z4));}
Output:
2*log(i) = 0.0+3.141593i4*log(sqrt(2)/2+sqrt(2)i/2) = 0.0+3.141593ilog(-1+0i) = 0.0+3.141593ilog(-1-0i) (the other side of the cut) = 0.0-3.141593i
(C99)(C99)(C99) | computes the complex base-e exponential (function)[edit] |
(C99)(C99) | computes natural (base-e) logarithm (\({\small \ln{x} }\)ln(x)) (function)[edit] |
C++ documentation forlog | |