Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I calculate log base 2 in c++? [duplicate]

Tags:

c++

Here is my code.

#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;

}

But above code gives error. Error code is : error C3861: 'log2': identifier not found. How can i calculate log2 using c++?

like image 816
user2036891 Avatar asked Nov 29 '22 16:11

user2036891


1 Answers

for example for log 3 in base 2

log (3) / log(2)

will do it.

#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    cout << log(3.0) / log(2.0) << endl;

}
like image 137
Hayri Uğur Koltuk Avatar answered Dec 12 '22 04:12

Hayri Uğur Koltuk