C++ 中复数的 log() 函数
在本文中我们将讨论 C++ STL 中 log() 函数的工作原理、语法和示例。
log() 函数是什么?
log() 函数是 C++ STL 中的一项内置函数,定义在 <complex> 头文件中。log() 返回复数的复自然对数。math 头文件中的 log() 和 complex 头文件中的 log() 的区别在于,log() 用于计算复对数,而 math 头文件中的 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)
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
安卓
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP