I just realized that in C++ std::log2((float)16) returns 4 but replacing with std::log10((float)16) / std::log10(2.0) returns 4.0000001902931812. I am storing my answer in a double variable.
I am not sure why ?
The replacement works nicely in windows calculator and matlab.