在C++中,可以使用cmath头文件中的log2函数来计算以2为底的对数。例如:
#include <iostream>
#include <cmath>
int main() {
double x = 16.0;
double result = log2(x);
std::cout << "log2(" << x << ") = " << result << std::endl;
return 0;
}
在此示例中,我们包含了cmath头文件,然后使用log2函数计算16的以2为底的对数,并输出结果。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:为什么要在C++中使用log2