在8位单片机中的浮点数运算开方,乘法,除法,反正切
int 1byte , long 4byte
本文引用地址:https://www.eepw.com.cn/article/201611/318613.htmBit data type cannot be used as a return value.
Double and float are NOT supported by the EM78 Series C Compiler.
开平方根
- unsignedlongsqrt_16(unsignedlongM)
- {
- unsignedlongN;
- inti;
- unsignedlongtmp,ttp;//结果、循环计数
- if(M==0)//被开方数,开方结果也为0
- return0;
- 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++;
- }
- }
- returnN;
- }
评论