新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > 在8位單片機中的浮點數(shù)運算開方,乘法,除法,反正切

在8位單片機中的浮點數(shù)運算開方,乘法,除法,反正切

作者: 時間:2016-11-20 來源:網(wǎng)絡 收藏
所用單片機:EM78系列,所用仿真器ICE468。

int 1byte , long 4byte

本文引用地址:http://butianyuan.cn/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;//結果、循環(huán)計數(shù)
  6. if(M==0)//被開方數(shù),開方結果也為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. }



評論


技術專區(qū)

關閉