您的位置:首页 > 其它

在8位单片机中的浮点数运算---开方,乘法,除法,反正切

2011-06-03 15:06 651 查看
所用单片机:EM78系列,所用仿真器ICE468。

int 1byte  , long 4byte

Bit data type cannot be used as a return value. 

Double and float are NOT supported by the EM78 Series C Compiler.

 

开平方根

unsigned long sqrt_16(unsigned long M)
{
unsigned long N;
int  i;
unsigned long tmp, ttp; // 结果、循环计数
if (M == 0) // 被开方数,开方结果也为0
return 0;
N = 0;
tmp = (M >> 30); // 获取最高位:B[m-1]
M <<= 2;
if (tmp > 1) // 最高位为1
{
N ++; // 结果当前位为1,否则为默认的0
tmp -= N;
}
for (i=15; i>0; i--) // 求剩余的15位
{
N <<= 1; // 左移一位
tmp <<= 2;
tmp += (M >> 30); // 假设
ttp = N;
ttp = (ttp<<1)+1;
M <<= 2;
if (tmp >= ttp) // 假设成立
{
tmp -= ttp;
N ++;
}
}
return N;
}


 

 

 

 

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  float byte c