scanf("%f",&n); z=Q_rsqrt(n); printf("平方根为%f\n",1.0/z); getch(); return 0; } 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. ...
4. ** float q_rsqrt( float number ) 5. */ 6. float Q_rsqrt( float number ) 7. { 8. long i; 9. float x2, y; 10. const float threehalfs = 1.5F; 11. x2 = number * 0.5F; 12. y = number; 13. long * ) &y; // evil floating point bit level hacking 14. // what...
因此肯定是更快的。 float Q_rsqrt( float number ) { long i; float x2, y; const float threehalfs = 1.5F; x2 = number * 0.5F; y = number; i = * ( long * ) &y; // evil floating point bit level hacking i =0x5f3759df- ( i >> 1 ); // what the fuck? y = * ( fl...
解法3:https://leetcode.com/discuss/110659/o-1-time-c-solution-inspired-by-q_rsqrt 大神的 O(1) 解法。 解法4: 完全平方数是一系列奇数之和,例如: 1 = 1 4 = 1 + 3 9 = 1 + 3 + 5 16 = 1 + 3 + 5 + 7 25 = 1 + 3 + 5 + 7 + 9 36 = 1 + 3 + 5 + 7 + 9 + 1...
importjava.lang.*; importjava.io.*; /* Name of the class has to be "Main" only if the class is public. */ classIdeone{ publicstaticvoidmain(String[]args){ String[]ab={"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r", ...
卡马克魔数开方 java #if !idppc /* ** float q_rsqrt( float number ) */ float Q_rsqrt( float number ) { long i; float x2, y; const float threehalfs = 1.5F; x2 = number * 0.5F; y = 卡马克魔数开方 java c/c++ 浮点数 迭代 .net 转载 精灵仙女 1月前 0阅读 ...
float Q_rsqrt( float number ) { long i; float x2, y; const float threehalfs = 1.5F; x2 = number * 0.5F; y = number; i = * ( long * ) &y; // evil floating point bit level hacking i = 0x5f3759df - ( i >> 1 ); // what the fuck?
#if !idppc /* ** float q_rsqrt( float number ) */ float Q_rsqrt( float number ) { long i; float x2, y; const float threehalfs = 1.5F; x2 = number * 0.5F; y = 卡马克魔数开方 java c/c++ 浮点数 迭代 .net 转载 精灵仙女 ...