I am not able to understand why the function (log_a_to_base_b) is returning a different value in comparison to the same operation if given with the input values in single line (Please refer below and code for much clearer explanation of problem)
-Basicaly why the function value and the variable x returned values are different as function return type is INT and the x is also storing the answer in INT shouldn't both answer be same
If given the same value The function value in the below code is coming as 3 while the x value in the below code is coming as 2
For refrence the log of 445943744 with base of 764 is 3
// C++ program to find log(a) on any base b
#include <bits/stdc++.h>
using namespace std;
int log_a_to_base_b(int a, int b)
{
return log2(a) / log2(b);
}
// Driver code
int main()
{
int a = 445943744;
int b = 764;
cout << log_a_to_base_b(a, b) << endl;
int x=log2(445943744)/log2(764);
cout<<x<<endl;
return 0;
}
// This code is contributed by shubhamsingh10, yousefonweb