Linux Kernel  3.7.1
dvb_math.h File Reference
`#include <linux/types.h>`

Go to the source code of this file.

## Functions

unsigned int intlog2 (u32 value)

unsigned int intlog10 (u32 value)

## Function Documentation

 unsigned int intlog10 ( u32 value )

computes log10 of a value; the result is shifted left by 24 bits

to use rational values you can use the following method: intlog10(value) = intlog10(value * 10^x) - x * 2^24

example: intlog10(1000) will give 3 << 24 = 3 * 2^24 due to the implementation intlog10(1000) might be not exactly 3 * 2^24

look at intlog2 for similar examples

Parameters
 value The value (must be != 0)
Returns
log10(value) * 2^24

returns: log10(value) * 2^24 wrong result if value = 0 (log10(0) is undefined)

we use the following method: log10(x) = log2(x) * log10(2)

Definition at line 123 of file dvb_math.c.

 unsigned int intlog2 ( u32 value )

computes log2 of a value; the result is shifted left by 24 bits

to use rational values you can use the following method: intlog2(value) = intlog2(value * 2^x) - x * 2^24

example: intlog2(8) will give 3 << 24 = 3 * 2^24 example: intlog2(9) will give 3 << 24 + ... = 3.16... * 2^24 example: intlog2(1.5) = intlog2(3) - 2^24 = 0.584... * 2^24

Parameters
 value The value (must be != 0)
Returns
log2(value) * 2^24

returns: log2(value) * 2^24 wrong result if value = 0 (log2(0) is undefined)

now we use a logtable after the following method:

log2(2^x * y) * 2^24 = x * 2^24 + log2(y) * 2^24 where x = msb and therefore 1 <= y < 2 first y is determined by shifting the value left so that msb is bit 31 0x00231f56 -> 0x8C7D5800 the result is y * 2^31 -> "significand" then the highest 9 bits are used for a table lookup the highest bit is discarded because it's always set the highest nine bits in our example are 100011000 so we would use the entry 0x18

last step we do is interpolation because of the limitations of the log table the error is that part of the significand which isn't used for lookup then we compute the ratio between the error and the next table entry and interpolate it between the log table entry used and the next one the biggest error possible is 0x7fffff (in our example it's 0x7D5800) needed value for next table entry is 0x800000 so the interpolation is (error / 0x800000) * (logtable_next - logtable_current) in the implementation the division is moved to the end for better accuracy there is also an overflow correction if logtable_next is 256

Definition at line 63 of file dvb_math.c.