clogf, clog, clogl

来自cppreference.com
< c‎ | numeric‎ | complex
在标头 <complex.h> 定义
floatcomplex       clogf(floatcomplex z );
(1) (C99 起)
doublecomplex      clog(doublecomplex z );
(2) (C99 起)
longdoublecomplex clogl(longdoublecomplex z );
(3) (C99 起)
在标头 <tgmath.h> 定义
#define log( z )
(4) (C99 起)
1-3) 计算 z 的复自然(底 e)对数,分支切割线沿负实轴。
4) 泛型宏:若 z 拥有 longdoublecomplex 类型,则调用 clogl,若 z 拥有 doublecomplex 类型,则调用 clog,若 z 拥有 floatcomplex 类型,则调用 clogf。若 z 为实数或整数,则该宏调用对应的实数函数(logfloglogl)。若 z 为虚数,则调用对应的复数版本。

目录

[编辑]参数

z - 复数实参

[编辑]返回值

若不发生错误,则返回 z 的复自然对数,其定义域为沿虚轴在区间 [−iπ, +iπ] 中,沿实轴为数学上无界的条带。

[编辑]错误处理及特殊值

报告的错误与 math_errhandling 一致。

若实现支持 IEEE 浮点算术,则

  • 考虑虚部符号,函数连续到分支切割上
  • clog(conj(z))==conj(clog(z))
  • z-0+0i,则结果为 -∞+πi 并引发 FE_DIVBYZERO
  • z+0+0i,则结果为 -∞+0i 并引发 FE_DIVBYZERO
  • zx+∞i(对于任何有限 x),则结果为 +∞+πi/2
  • zx+NaNi(对于任何有限 x),则结果为 NaN+NaNi 并可能引发 FE_INVALID
  • z-∞+yi(对于任何有限正 y),则结果为 +∞+πi
  • z+∞+yi(对于任何有限正 y),则结果为 +∞+0i
  • z-∞+∞i,则结果为 +∞+3πi/4
  • z+∞+∞i,则结果为 +∞+πi/4
  • z±∞+NaNi,则结果为 +∞+NaNi
  • zNaN+yi(对于任何有限 y),则结果为 NaN+NaNi 并可能引发 FE_INVALID
  • zNaN+∞i,则结果为 +∞+NaNi
  • zNaN+NaNi,则结果为 NaN+NaNi

[编辑]注意

拥有极坐标表示 (r,θ) 的复数 z 的自然对数等于 ln r + i(θ+2nπ),其主值为 ln 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));// 或 C11 中的 clog(CMPLX(-1, -0.0))printf("log(-1-0i) (the other side of the cut) = %.1f%+fi\n", creal(z4), cimag(z4));}

输出:

2*log(i) = 0.0+3.141593i 4*log(sqrt(2)/2+sqrt(2)i/2) = 0.0+3.141593i log(-1+0i) = 0.0+3.141593i log(-1-0i) (the other side of the cut) = 0.0-3.141593i

[编辑]引用

  • C11 标准(ISO/IEC 9899:2011):
  • 7.3.7.2 The clog functions (第 195 页)
  • 7.25 Type-generic math <tgmath.h> (第 373-375 页)
  • G.6.3.2 The clog functions (第 543-544 页)
  • G.7 Type-generic math <tgmath.h> (第 545 页)
  • C99 标准(ISO/IEC 9899:1999):
  • 7.3.7.2 The clog functions (第 176-177 页)
  • 7.22 Type-generic math <tgmath.h> (第 335-337 页)
  • G.6.3.2 The clog functions (第 478-479 页)
  • G.7 Type-generic math <tgmath.h> (第 480 页)

[编辑]参阅

(C99)(C99)(C99)
计算复数的 e 底指数
(函数)[编辑]
(C99)(C99)
计算自然对数(底为 e)(ln(x)
(函数)[编辑]
log 的 C++ 文档
close