Very cool algorithm used in (among other things) redis.
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;
}
https://en.wikipedia.org/wiki/Fast_inverse_square_roothttp://www.drdobbs.com/cpp/misusing-floating-point-arithmeti...
http://www.drdobbs.com/cpp/some-programs-are-poorly-designed...
https://en.wikipedia.org/wiki/B-tree
Could you describe your current implementation and its elegance?
generate a random number between 0:100 if the number is 0-30 the Ad 1 has to be shown if the number is 30-70 the Ad 1 has to be shown else RTB is to be called
The servers can be now independent and no need to share the state, or have a lock based counter. For large number of requests, and with a good random number generator, you will get good results.
Pretty standard in what context? Can you elaborate? Is there a name for the algorithm?
What is RTB?
One that comes to mind is XOR-swap. It's cute, but it's likely slower than using a temp var.
Some of the integer population count algos (1's counting) are clever.
Also, original Doom source has some neat tricks.