Definition of "programming trick"

See “Type-level instant insanity”, page 42, of this. He basically uses Haskell’s type system as a declarative programming language in its own right.

>A good example fitting this description is the inverse square root function of 32-bit floats that’s used in Quake III.

Oh, this is a nice one, yes. It threw me at first - I’m thinking an inverse square root function is squaring. But by “inverse” here is meant the reciprocal, not the inverse of the function.

The comment “John Carmack must have used genuine black magic to find this number” is amusing. Since Carmack is a programmer, mightn’t he have written a program to hunt for it?

Though, perhaps this is in a different category than programming tricks. He has an algorithm that is very fast for mathematical reasons, independent of how its execution is programmed.

It should be noted that this produces slower code than the straightforward implementation with a temp variable, because with this method the compiler doesn’t know it can just load two registers and perform a swap opcode, as opposed to generating a lot of integer math.