From Coral Stork, 7 Years ago, written in Plain Text.
- go back
Embed
Viewing differences between and Untitled
  1. float fastsqrt(float val)  {
  2.         union
  3.         {
  4.                 int tmp;
  5.                 float val;
  6.         } u;
  7.         u.val = val;
  8.         u.tmp -= 1<<23; /* Remove last bit so 1.0 gives 1.0 */
  9.         /* tmp is now an approximation to logbase2(val) */
  10.         u.tmp >>= 1; /* divide by 2 */
  11.         u.tmp += 1<<29; /* add 64 to exponent: (e+127)/2 =(e/2)+63, */
  12.         /* that represents (e/2)-64 but we want e/2 */
  13.         return u.val;
  14. }