# Logarithm, LUT and how to make it non-linear

Currently I calculate log as following:

#define MAXLOG 1001
double myloglut[MAXLOG];
void MyLogCreate()
{
int i;
double exp, expinc;
expinc = (2.0 - 0.1) / MAXLOG;
for (i = 0, exp = 0.1; i <= MAXLOG; ++i, exp += expinc)
myloglut[i] = log(exp);
myloglut[478] = 0; // this one need to be precise
}

double MyLog(double v)
{
int idx = (int)((MAXLOG*(v - 0.1)) / (2.0 - 0.1));
return myloglut[idx];
}


As you can see I'm interested only in range 0.1 - 2.0. However, I need more precision around 0. How can I achieve that non linear calculation? Also is there any way to use some interpolation in this function for better precision?

-
What is the goal you're trying to achieve by writing these routines? –  Hurkyl Dec 6 '12 at 9:48
It's been used in Rhumb geo distance calculation. –  Pablo Dec 6 '12 at 10:00

$$\log(m \cdot 2^e) = \log m + e \log 2$$