Created
October 13, 2011 04:13
-
-
Save shihongzhi/1283350 to your computer and use it in GitHub Desktop.
求得的是 开平方的倒数,具体原理不懂
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 来至 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