#include <cmath>
#include <iostream>
usingnamespace std;
int main()
{
// n
double n = log(125)/log(5);
// n2
int base = 5;
int number = 30;
double n2 = log10((number + 1) * (base - 1) + 1) / log10(base);
cout << (int) n << " --> " << (int) n2 << endl;
}
log(125)/log(5) returns three as expected.
(number + 1) * (base - 1) + 1 is 125. But If I put that as an argument into the log function and cast it into an int it gives me 2. I am seriously confused.
Doubles aren't much precise, so the value of n2 may be 2.99999 or something like that.
When you cast a double into an integer the decimal digits are truncated.