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