新闻中心

EEPW首页>嵌入式系统>设计应用> 在8位单片机中的浮点数运算开方,乘法,除法,反正切

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

作者: 时间:2016-11-20 来源:网络 收藏
所用单片机:EM78系列,所用仿真器ICE468。

int 1byte , long 4byte

本文引用地址://m.amcfsurvey.com/article/201611/318613.htm

Bit data type cannot be used as a return value.

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

开平方根

  1. unsignedlongsqrt_16(unsignedlongM)
  2. {
  3. unsignedlongN;
  4. inti;
  5. unsignedlongtmp,ttp;//结果、循环计数
  6. if(M==0)//被开方数,开方结果也为0
  7. return0;
  8. N=0;
  9. tmp=(M>>30);//获取最高位:B[m-1]
  10. M<<=2;
  11. if(tmp>1)//最高位为1
  12. {
  13. N++;//结果当前位为1,否则为默认的0
  14. tmp-=N;
  15. }
  16. for(i=15;i>0;i--)//求剩余的15位
  17. {
  18. N<<=1;//左移一位
  19. tmp<<=2;
  20. tmp+=(M>>30);//假设
  21. ttp=N;
  22. ttp=(ttp<<1)+1;
  23. M<<=2;
  24. if(tmp>=ttp)//假设成立
  25. {
  26. tmp-=ttp;
  27. N++;
  28. }
  29. }
  30. returnN;
  31. }



评论


技术专区

关闭