18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * dvb-math provides some complex fixed-point math
38c2ecf20Sopenharmony_ci * operations shared between the dvb related stuff
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2006 Christoph Pfister (christophpfister@gmail.com)
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * This library is free software; you can redistribute it and/or modify
88c2ecf20Sopenharmony_ci * it under the terms of the GNU Lesser General Public License as
98c2ecf20Sopenharmony_ci * published by the Free Software Foundation; either version 2.1 of
108c2ecf20Sopenharmony_ci * the License, or (at your option) any later version.
118c2ecf20Sopenharmony_ci *
128c2ecf20Sopenharmony_ci * This program is distributed in the hope that it will be useful,
138c2ecf20Sopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of
148c2ecf20Sopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
158c2ecf20Sopenharmony_ci * GNU Lesser General Public License for more details.
168c2ecf20Sopenharmony_ci */
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci#ifndef __DVB_MATH_H
198c2ecf20Sopenharmony_ci#define __DVB_MATH_H
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#include <linux/types.h>
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci/**
248c2ecf20Sopenharmony_ci * intlog2 - computes log2 of a value; the result is shifted left by 24 bits
258c2ecf20Sopenharmony_ci *
268c2ecf20Sopenharmony_ci * @value: The value (must be != 0)
278c2ecf20Sopenharmony_ci *
288c2ecf20Sopenharmony_ci * to use rational values you can use the following method:
298c2ecf20Sopenharmony_ci *
308c2ecf20Sopenharmony_ci *   intlog2(value) = intlog2(value * 2^x) - x * 2^24
318c2ecf20Sopenharmony_ci *
328c2ecf20Sopenharmony_ci * Some usecase examples:
338c2ecf20Sopenharmony_ci *
348c2ecf20Sopenharmony_ci *	intlog2(8) will give 3 << 24 = 3 * 2^24
358c2ecf20Sopenharmony_ci *
368c2ecf20Sopenharmony_ci *	intlog2(9) will give 3 << 24 + ... = 3.16... * 2^24
378c2ecf20Sopenharmony_ci *
388c2ecf20Sopenharmony_ci *	intlog2(1.5) = intlog2(3) - 2^24 = 0.584... * 2^24
398c2ecf20Sopenharmony_ci *
408c2ecf20Sopenharmony_ci *
418c2ecf20Sopenharmony_ci * return: log2(value) * 2^24
428c2ecf20Sopenharmony_ci */
438c2ecf20Sopenharmony_ciextern unsigned int intlog2(u32 value);
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci/**
468c2ecf20Sopenharmony_ci * intlog10 - computes log10 of a value; the result is shifted left by 24 bits
478c2ecf20Sopenharmony_ci *
488c2ecf20Sopenharmony_ci * @value: The value (must be != 0)
498c2ecf20Sopenharmony_ci *
508c2ecf20Sopenharmony_ci * to use rational values you can use the following method:
518c2ecf20Sopenharmony_ci *
528c2ecf20Sopenharmony_ci *   intlog10(value) = intlog10(value * 10^x) - x * 2^24
538c2ecf20Sopenharmony_ci *
548c2ecf20Sopenharmony_ci * An usecase example:
558c2ecf20Sopenharmony_ci *
568c2ecf20Sopenharmony_ci *	intlog10(1000) will give 3 << 24 = 3 * 2^24
578c2ecf20Sopenharmony_ci *
588c2ecf20Sopenharmony_ci *   due to the implementation intlog10(1000) might be not exactly 3 * 2^24
598c2ecf20Sopenharmony_ci *
608c2ecf20Sopenharmony_ci * look at intlog2 for similar examples
618c2ecf20Sopenharmony_ci *
628c2ecf20Sopenharmony_ci * return: log10(value) * 2^24
638c2ecf20Sopenharmony_ci */
648c2ecf20Sopenharmony_ciextern unsigned int intlog10(u32 value);
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci#endif
67