这是我的代码.
#include <iostream>
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include <cmath>
#include <functional>
using namespace std;
void main()
{
cout<<log2(3.0)<<endl;
}
Run Code Online (Sandbox Code Playgroud)
但上面的代码给出了错误.错误代码是:错误C3861:'log2':找不到标识符.如何使用c ++计算log2?
例如,对于基数2中的log 3
log (3) / log(2)
Run Code Online (Sandbox Code Playgroud)
会做的.
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
cout << log(3.0) / log(2.0) << endl;
}
Run Code Online (Sandbox Code Playgroud)
使用高中数学:
log_y(x) = ln(x)/ln(y)
Run Code Online (Sandbox Code Playgroud)
但我同意,那里没有这样的实用功能有点奇怪.这可能是由于这些功能几乎直接映射到FPU.
但是不要担心使用这种"扩展"方式.数学不会改变.该公式至少在接下来的几个生命周期内有效.