#define INT16U unsigned int
#define INT16S int#define INT32U unsigned long
#define INT32S long
#define INT64S long long
#define INT64U unsigned long long
INT32U swwRoot(INT64U dwNumber)
{
INT8U ii;
INT64U dwSquareRoot;
if(dwNumber == 0)
return (0);
if(dwNumber <= 4194304)
dwSquareRoot = dwNumber / 1024 + 63;
else if (dwNumber <= 134217728)
dwSquareRoot = dwNumber / 4096 + 255;
else if(dwNumber <= 4294967296)
dwSquareRoot = dwNumber / 16384 + 1023;
else if(dwNumber <= 137438953472)
dwSquareRoot = dwNumber / 65536 + 4095;
else if(dwNumber <= 1099511627776)
dwSquareRoot = dwNumber / 262144 + 16383;
else if(dwNumber <= 4398046511104)
dwSquareRoot = dwNumber / 1048576 + 65535;
else if(dwNumber <= 140737488355328)
dwSquareRoot = dwNumber / 4194304 + 262143;
else if(dwNumber <= 4503599627370496U)
dwSquareRoot = dwNumber / 16777216 + 1048575;
else if(dwNumber <= 144115188075855872)
dwSquareRoot = dwNumber / 67108864 + 4194303;
else
dwSquareRoot = dwNumber / 268435456 + 16777215;
for (ii=0;ii<5;ii++)
dwSquareRoot=(dwSquareRoot+dwNumber/dwSquareRoot)/2;
return((INT32U)dwSquareRoot);
}
在调用函数swwRoot()传入大于32位值时出现内存出错的情况,偶尔导致我中断的控制数据出现错误,似乎内存出错了,这个是在主程序的一个任务中调用,使用的是UCOS 的一个子任务调用它。何解??不能运行64位吗?
mangui zhang:没跑过ucos你看看是否是堆栈等设置太小造成的