Skip to content

Instantly share code, notes, and snippets.

@shihongzhi
Created October 13, 2011 04:13
Show Gist options
  • Save shihongzhi/1283350 to your computer and use it in GitHub Desktop.
Save shihongzhi/1283350 to your computer and use it in GitHub Desktop.
求得的是 开平方的倒数,具体原理不懂
/* 来至 Quake 3 的源码 */
//求得的是 开平方的倒数,具体原理不懂
float CarmSqrt(float x){
union{
int intPart;
float floatPart;
} convertor;
union{
int intPart;
float floatPart;
} convertor2;
convertor.floatPart = x;
convertor2.floatPart = x;
convertor.intPart = 0x1FBCF800 + (convertor.intPart >> 1);
convertor2.intPart = 0x5f3759df - (convertor2.intPart >> 1);
return 0.5f*(convertor.floatPart + (x * convertor2.floatPart));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment