In order to get started with CORDIC for log10, I implemented the algorithm derived in this PDF, pp6:
#include <stdio.h> #include <math.h> // https://www.mikrocontroller.net/attachment/31117/cordic1.pdf float logf_cordic (float x, int B) { float z = 0.0f; for (int i = 1; i <= B; i++) { if (x > 1.0f) { printf ("-"); x = x - ldexpf (x, -i); z = z - log10f (1.0f - ldexpf (1.0f, -i)); } else { printf ("+"); x = x + ldexpf (x, -i); z = z - log10f (1.0f + ldexpf (1.0f, -i)); } } return z; } This is a straight forward C99 implementation of the code from the paper, where I used ldexpf(x,n) to compute x·2n. The paper claims that the method converges for 0.4194 < x < 3.4627. The program uses 1 ≤ x ≤ 2. The complete C99 code below prints:
+--+--+--+-+-+++--++ x = 1.00000: y = -0.000000, dy = -1.487272e-07 -+++++++++++++++++++ x = 1.12500: y = +0.099773, dy = +4.862081e-02 -+++++++++++++++++++ x = 1.25000: y = +0.099773, dy = +2.863325e-03 -+++-+--+-+--+-++--+ x = 1.37500: y = +0.138302, dy = -4.023314e-07 -++-+--++----+++--+- x = 1.50000: y = +0.176091, dy = -2.831221e-07 -+-+++++-++-++-++++- x = 1.62500: y = +0.210854, dy = +2.831221e-07 -+-+-+-+++++--+---++ x = 1.75000: y = +0.243038, dy = +2.235174e-07 -+--++-+--+---+---+- x = 1.87500: y = +0.273001, dy = +0.000000e+00 -+---+--+++--------- x = 2.00000: y = +0.301030, dy = -5.960464e-08 So it works as expected, except for x = 1.125, 1.25 where the error is big and doesn't decrease when computing with more iterations. I am now staring at that code for hours, but cannot find what I am missing...
Complete C99 code
#include <stdio.h> #include <math.h> float logf_cordic (float x, int B) { float z = 0.0f; for (int i = 1; i <= B; i++) { if (x > 1.0f) { printf ("-"); x = x - ldexpf (x, -i); z = z - log10f (1.0f - ldexpf (1.0f, -i)); } else { printf ("+"); x = x + ldexpf (x, -i); z = z - log10f (1.0f + ldexpf (1.0f, -i)); } } return z; } int main (int argc, char *argv[]) { int ex = 3; int B = 20; if (argc >= 2) sscanf (argv[1], "%i", &ex); if (argc >= 3) sscanf (argv[2], "%i", &B); if (ex < 0) ex = 0; if (ex > 16) ex = 16; if (B > 100) B = 100; int n = 1 << ex; float dx = 1.0f / n; for (int i = 0; i <= n; ++i) { float x = 1.0f + i * dx; float y = logf_cordic (x, B); float dy = y - log10f (x); printf (" x = %.5f: y = %+f, dy = %+e\n", (double) x, (double) y, (double) dy); } return 0; } For reference, here is the algo as presented in the paper:
log10(x){ z = 0; for ( i=1;i=<B;i++ ){ if (x > 1) x = x - x*2^(-i); z = z - log10(1-2^(-i)); else x = x + x*2^(-i); z = z - log10(1+2^(-i)); } return(z) } 
floattodoubleand increase stepex, you can see that all values below ≈1.25826are not accurate. Probably lower bound estimation0.4194is not correct. Note0.4194 * 3 ≈ 1.25826xcan be expanded as a product with factors 1±2^{-k}, which is wrong.