log()函数用于C ++中的复数

在本文中,我们将讨论log()C ++ STL中函数的工作,语法和示例。

功能是什么log()

log()函数是C ++ STL中的内置函数,在<complex>头文件中定义。log()返回复数值的复自然对数值。log()数学头文件中和log()复杂头文件中的区别在于,它用于计算复杂对数,log()而数学头文件中的计算常规对数。

语法

template<class T> complex<T> log(const complex<T>& x);

参数

此函数接受一个参数,该参数是一个复杂的值,我们必须查找其日志。

返回值

我们要计算的x的对数值。

示例

Input: complex<double> C_number(-7.0, 1.0);
   log(C_number);
Output: log of (-7,1) is (1.95601,2.9997)
#include <bits/stdc++.h>
using namespace std;
int main() {
   complex<double> C_number(-7.0, 1.0);
   cout<<"log of "<<C_number<<" is "<<log(C_number)<< endl;
   return 0;
}

输出结果

如果我们运行上面的代码,它将生成以下输出-

log of (-7,1) is (1.95601,2.9997)

示例

#include <bits/stdc++.h>
using namespace std;
int main() {
   complex<double> C_number(-4.0, -1.0);
   cout<<"log of "<< C_number<< " is "<<log(C_number);
   return 0;
}

输出结果

如果我们运行上面的代码,它将生成以下输出-

log of (-4,-1) is (1.41661,-2.89661)