fork download
  1. #include<iostream>
  2. using std::cout;
  3. float Q_rsqrt( float number ) { long i; float x2, y;
  4. const float threehalfs = 1.5F;
  5.  
  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. }
  15. int main(void) { cout<<Q_rsqrt(23.22); }
Success #stdin #stdout 0s 4380KB
stdin
Standard input is empty
stdout
0.207277