Tricks that work on floating point are sometimes useful and not listed there..
Make float sortable as integer. (the reason you might wish to do this is that integer comparisons are faster and run on more ports, also you won't get unsortable data from NAN). You can undo the transform by calling this fxn again. You only need this with a mix of positive/negative floats, if they are all positive you can skip this.
int i = cast_int(f);
shift_right_sign_bits(i, 31) & 0x7FFFFFFF) ^ i
Scale float by powers of 2
Cast a float to integer and add 0x00800000 * N(N being the power of 2). Subtract to divide. Fails with 0 value float.
Not super useful unless you already have the float in the integer domain for some other reason, also integer adds/subs run on more ports and are 1 cycle.
The fast sqrt function is well known but you can do this for other powers of 2
//An approximate pow(a, 1/4)
float fastPow_1_4(float a) {
return asfloat((asuint(a) >> 2u) + 798700996u);
}
//An approximate pow(a, 1/8)
float fastPow_1_8(float a) {
return asfloat((asuint(a) >> 3u) + 931853847u);
}
//An approximate pow(a, 1/16)
float fastPow_1_16(float a) {
return asfloat((asuint(a) >> 4u) + 998350438u);
}
//An approximate pow(a, 1/32)
float fastPow_1_32(float a) {
return asfloat((asuint(a) >> 5u) + 1031705320u);
}
They are very low accuracy as they don't have a newton raphson step, and were just intended for stuff like graphics where accuracy isn't always important.