I would avoid pow for this. This, as you know, is difficult to implement correctly. There are many SO questions in which people were burned due to poor implementation of pow in their standard library.
You can also save a lot of pain by working in a natural base instead of base 10. You will get a code that looks like this:
long double foo = m * logl(n); foo = fmodl(foo, logl(10.0)) + some_epsilon; sprintf(some_string, "%.9Lf", expl(foo));
to compute the corresponding analogue of m log(n) . Note that the largest m * logl(n) that can occur is slightly larger than 2e10 . When you divide this by 2 64 and round to the nearest power of two, you will see that ulp foo in the worst case is 2 -29 . This means, in particular, that you cannot get more than 8 digits from this method using long double s, even with an ideal implementation.
some_epsilon will be the smallest long double that makes expl(foo) always superior to the mathematically correct result; I did not calculate it exactly, but it should be of the order of 1e-9 .
In light of the difficulties with precision, I can suggest using a library like MPFR instead of long double s. You can also get something to work with the double double trick and the four-point precision exp , log and fmod .
source share