I was figuring out the difference between log(3)
and log10(3)
, using this code:
void testPrecisionError() {
cout
<< log(243) / log(3) << " : "
<< int(log(243) / log(3)) << " : "
<< endl;
cout
<< log10(243) / log10(3) << " : "
<< int(log10(243) / log10(3)) << " : ")
<< endl;
}
The output is:
5 : 4 // I think it is 4.999999 underlying
5 : 5
I found out that 4.999999
is printed out as 5
.
Why doesn't C++ print it as 4.99999
like Java does?
I guess I could no more cout
to convince myself that there is NO PRECISON LOSS !