1*4882a593Smuzhiyun /* 2*4882a593Smuzhiyun * dvb-math provides some complex fixed-point math 3*4882a593Smuzhiyun * operations shared between the dvb related stuff 4*4882a593Smuzhiyun * 5*4882a593Smuzhiyun * Copyright (C) 2006 Christoph Pfister (christophpfister@gmail.com) 6*4882a593Smuzhiyun * 7*4882a593Smuzhiyun * This library is free software; you can redistribute it and/or modify 8*4882a593Smuzhiyun * it under the terms of the GNU Lesser General Public License as 9*4882a593Smuzhiyun * published by the Free Software Foundation; either version 2.1 of 10*4882a593Smuzhiyun * the License, or (at your option) any later version. 11*4882a593Smuzhiyun * 12*4882a593Smuzhiyun * This program is distributed in the hope that it will be useful, 13*4882a593Smuzhiyun * but WITHOUT ANY WARRANTY; without even the implied warranty of 14*4882a593Smuzhiyun * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15*4882a593Smuzhiyun * GNU Lesser General Public License for more details. 16*4882a593Smuzhiyun */ 17*4882a593Smuzhiyun 18*4882a593Smuzhiyun #ifndef __DVB_MATH_H 19*4882a593Smuzhiyun #define __DVB_MATH_H 20*4882a593Smuzhiyun 21*4882a593Smuzhiyun #include <linux/types.h> 22*4882a593Smuzhiyun 23*4882a593Smuzhiyun /** 24*4882a593Smuzhiyun * intlog2 - computes log2 of a value; the result is shifted left by 24 bits 25*4882a593Smuzhiyun * 26*4882a593Smuzhiyun * @value: The value (must be != 0) 27*4882a593Smuzhiyun * 28*4882a593Smuzhiyun * to use rational values you can use the following method: 29*4882a593Smuzhiyun * 30*4882a593Smuzhiyun * intlog2(value) = intlog2(value * 2^x) - x * 2^24 31*4882a593Smuzhiyun * 32*4882a593Smuzhiyun * Some usecase examples: 33*4882a593Smuzhiyun * 34*4882a593Smuzhiyun * intlog2(8) will give 3 << 24 = 3 * 2^24 35*4882a593Smuzhiyun * 36*4882a593Smuzhiyun * intlog2(9) will give 3 << 24 + ... = 3.16... * 2^24 37*4882a593Smuzhiyun * 38*4882a593Smuzhiyun * intlog2(1.5) = intlog2(3) - 2^24 = 0.584... * 2^24 39*4882a593Smuzhiyun * 40*4882a593Smuzhiyun * 41*4882a593Smuzhiyun * return: log2(value) * 2^24 42*4882a593Smuzhiyun */ 43*4882a593Smuzhiyun extern unsigned int intlog2(u32 value); 44*4882a593Smuzhiyun 45*4882a593Smuzhiyun /** 46*4882a593Smuzhiyun * intlog10 - computes log10 of a value; the result is shifted left by 24 bits 47*4882a593Smuzhiyun * 48*4882a593Smuzhiyun * @value: The value (must be != 0) 49*4882a593Smuzhiyun * 50*4882a593Smuzhiyun * to use rational values you can use the following method: 51*4882a593Smuzhiyun * 52*4882a593Smuzhiyun * intlog10(value) = intlog10(value * 10^x) - x * 2^24 53*4882a593Smuzhiyun * 54*4882a593Smuzhiyun * An usecase example: 55*4882a593Smuzhiyun * 56*4882a593Smuzhiyun * intlog10(1000) will give 3 << 24 = 3 * 2^24 57*4882a593Smuzhiyun * 58*4882a593Smuzhiyun * due to the implementation intlog10(1000) might be not exactly 3 * 2^24 59*4882a593Smuzhiyun * 60*4882a593Smuzhiyun * look at intlog2 for similar examples 61*4882a593Smuzhiyun * 62*4882a593Smuzhiyun * return: log10(value) * 2^24 63*4882a593Smuzhiyun */ 64*4882a593Smuzhiyun extern unsigned int intlog10(u32 value); 65*4882a593Smuzhiyun 66*4882a593Smuzhiyun #endif 67