Cordic算法之log应用

3,686次阅读
没有评论
#include
using namespace std;

int fxlog(int x) {
	int t, y;


	y = 0x157cd3;
	if (x < 0x00008000) x <<= 16, y -= 0xb1721;
	if (x < 0x00800000) x <<= 8, y -= 0x58b91;
	if (x < 0x08000000) x <<= 4, y -= 0x2c5c8;
	if (x < 0x20000000) x <<= 2, y -= 0x162e4;
	if (x < 0x40000000) x <<= 1, y -= 0x0b172; 	t = x + (x >> 1); 
	if ((t & 0x80000000) == 0)
	{
		x = t, y -= 0x067cd;
	}
	t = x + (x >> 2);
	if ((t & 0x80000000) == 0)
	{
		x = t, y -= 0x03920;
	}
	t = x + (x >> 3); 
	if ((t & 0x80000000) == 0)
	{
		x = t, y -= 0x01e27;
	}
	t = x + (x >> 4);
	if ((t & 0x80000000) == 0)
	{
		x = t, y -= 0x00f85;
	}
	t = x + (x >> 5); 
	if ((t & 0x80000000) == 0)
	{
		x = t, y -= 0x007e1;
	}
	t = x + (x >> 6);
	if ((t & 0x80000000) == 0)
	{
		x = t, y -= 0x003f8;
	}
	t = x + (x >> 7);
	if ((t & 0x80000000) == 0)
	{
		x = t, y -= 0x001fe;
	}
	x = 0x80000000 - x;	
	y = (y - (x >> 15)) 
	return y;
}



int _tmain(int argc, _TCHAR* argv[])
{
	int a = 2000;
	
	int hello = fxlog(a);
	//int test = fxexp(2);
	cout << hello>>16 <<endl;
	return 0;
}
admin
版权声明:本站原创文章,由admin2016-01-28发表,共计716字。
转载提示:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(没有评论)