0

I can't figure out why l10 variable in code below isn't equal to l variable for values 243 and 59049 (probably there is some other values).

They are both double values. So I think that the floor() function should return same results for both and these results should be equal.

But in log() case floored value decreased by one and in log10() case floored value is still the same.

#include <typeinfo>
using namespace std;

int main() {
    for (int i = 0; i < 1000000; i++)
    {
        double l10 = log10(i)/log10(3);
        double l = log(i)/log(3);
        if (floor(l10) != floor(l)){
            cout << floor(l10) << " " << floor(l) << 
                " types: " << typeid(l10).name() << typeid(l).name() << endl;
            cout << "number: " << i << endl << endl;
        }
    }
}

Output:

5 4 types: dd
number: 243

10 9 types: dd
number: 59049

0 Answers0