3 ms·
The point is to not think of the bits as the representation of a decimal number. For example, if I need to know in which quadrant an angle is, I just need to lo
by yiyus 6y ago
The point is to not think of the bits as the representation of a decimal number. For example, if I need to know in which quadrant an angle is, I just need to look at the first two bits, independently of the precision (which we change just shifting and truncating). But I do not mind if 90 degrees are equal to 64 or 1073741824 "sectors".
I think this is another good example where a binary representation (and a shift) can be a more natural way to approach the problem.
- pdehaan 6y agoNot just more natural, it also lends itself to better accuracy and/or efficiency in some cases too. As a quick example, if you're writing a numerical approximation or even just a LUT for sin(x), you can get away with only approximating/storing values for a reduced range by using some bit twiddling. The top bit becomes sign of output if you XOR it out first, the next bit lets you take advantage of sin(pi/2-x) = sin(x+pi/2) to half the input range again, eek out symmetry for the next bit and you can nearly approximate sin(x) as a linear function for some use cases.