一般的单片机开方都有什么方法哪

2020-01-23 14:32发布

如题
楼下的看错了,我说开方运算
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
18条回答
millwood0
2020-01-25 01:34
搜索  卡马克


:)

google "doom fast inverse square root"

and let me post it here:

  1. float Q_rsqrt( float number )
  2. {
  3.         long i;
  4.         float x2, y;
  5.         const float threehalfs = 1.5F;

  6.         x2 = number * 0.5F;
  7.         y  = number;
  8.         i  = * ( long * ) &y;                       // evil floating point bit level hacking
  9.         i  = 0x5f3759df - ( i >> 1 );               // what the fuck?
  10.         y  = * ( float * ) &i;
  11.         y  = y * ( threehalfs - ( x2 * y * y ) );   // 1st iteration
  12. //      y  = y * ( threehalfs - ( x2 * y * y ) );   // 2nd iteration, this can be removed

  13.         return y;
  14. }
复制代码This is probably the most fascinating piece of code anyone has written over the last 50 years. Bar none.

and we still don't know who exactly wrote it, and how s/he came up with the magic number.

enjoy.

一周热门 更多>