About
Accounts
Friends

Loading…melovespot 7 months ago

Loading…kauah about 2 hours ago

Loading…Advertime over 3 years ago

Loading…RekrutK about 3 hours ago

Loading…bagosta over 5 years ago

Loading…doener about 9 hours ago

Loading…Nostradamus68 11 days ago

Loading…herrurbach about 1 month ago

Loading…evelina 3 days ago

Loading…datura over 2 years ago
 +25
Click here to check if anything new just came in.
May 26 2015
May 22 2015
May 19 2015
“— Fast inverse square root  Wikipedia, the free encyclopediaThe following code is the fast inverse square root implementation from Quake III Arena, stripped of C preprocessor directives, but including the exact original comment text:^{[4]}
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 = * ( float * ) &i; y = y * ( threehalfs  ( x2 * y * y ) ); // 1st iteration // y = y * ( threehalfs  ( x2 * y * y ) ); // 2nd iteration, this can be removed return y; }In order to determine the inverse square root, an approximation for would be determined by the software, then some numerical method would revise that approximation until it came within an acceptable error range of the actual result. Common software methods in the early 1990s drew a first approximation from a lookup table.^{[5]} This bit of code proved faster than table lookups and approximately four times faster than regular floating point division.^{[6]} Some loss of precision occurred, but was offset by the significant gains in performance.^{[7]} The algorithm was designed with the IEEE 7541985 32bit floating point specification in mind, but investigation from Chris Lomont and later Charles McEniry showed that it could be implemented in other floating point specifications.
The advantages in speed offered by the fast inverse square root kludge came from treating the longword^{[note 1]} containing the floating point number as an integer then subtracting it from a specific constant, 0x5f3759df. The purpose of the constant is not immediately clear to someone viewing the code, so, like other such constants found in code, it is often called a "magic number".^{[1]}^{[8]}^{[9]}^{[10]} This integer subtraction and bit shift results in a longword which when treated as a floating point number is a rough approximation for the inverse square root of the input number. One iteration of Newton's method is performed to gain some precision, and the code is finished. The algorithm generates reasonably accurate results using a unique first approximation for Newton's method; however, it is much slower and less accurate than using the SSE instruction
”rsqrtss
on x86 processors also released in 1999
Maybe Soup is currently being updated? I'll try again automatically in a few seconds...