Solved! Go to Solution.
When trying to do computation rapidly on real-world quantities, it is often helpful to look at integers as fractions of a "full scale" value. This has the nice feature that multiplication of two quantities less than 1 will always give a result less than 1. So to scale a quantity, you just do a multiply and take the most significant bits. No shifting involved, just word operations.
Its real easy in assembler, but a little awkward in C, so hiding it in some function written in assembly may be a good idea.
It seems like a fractional arithmetic class in C++ would make this easy, but I'm not aware of one. (I haven't had occasion to look.)
When trying to do computation rapidly on real-world quantities, it is often helpful to look at integers as fractions of a "full scale" value. This has the nice feature that multiplication of two quantities less than 1 will always give a result less than 1. So to scale a quantity, you just do a multiply and take the most significant bits. No shifting involved, just word operations.
Its real easy in assembler, but a little awkward in C, so hiding it in some function written in assembly may be a good idea.
It seems like a fractional arithmetic class in C++ would make this easy, but I'm not aware of one. (I haven't had occasion to look.)