Fredrik Fryklund: Quake 3, binary numbers and bitwise operations
Tid: Fr 2019-01-25 kl 15.15 - 16.00
Föreläsare: Fredrik Fryklund
Plats: Room 3418, Lindstedtsvägen 25, 4th floor, Department of Mathematics, KTH
We all know that a computer store data as ones and zeros, or in binary numbers, and our knowledge does not, usually, extend far beyond that. During this talk I will introduce various representation of numbers in bits and how a computer executes opeartions such as multiplication, division etc or handle Bolean algebra. Furthermore, how precise results can we expect, considering that the memory is finite? With this background I will explain a fast algorithm for computing the inverse square root of a positive floating point number. Its origin is from the computer game Quake III Arena. The following code is an extract of the fast inverse square root implementation, in C, from Quake III Arena, including the exact original comment text:
Line 560: i = * ( long * ) &y; // evil floating point bit level hacking
Line 561: i = 0x5f3759df - ( i >> 1 ); // what the fuck?
Fast inverse square root in action: https://www.youtube.com/watch?v=uc1gLyHnK5E