by Dan East » Jul 12, 2001 @ 11:06am
The FixedPointMath.c routines are not being used at this time. After the PQ project was at a stable point I foolishly decided to attempt a global, generic replacement of all Floating point math with Fixed point. I created a new fixed point type, and the routines you see in FixedPointMath to handle fixed point operations. I then went through the source and replaced floating point operators (+, -, *, etc) with function calls to my new routines. After a huge amount of effort, it wouldn't work. What I found was that the range and precision of the various floating point vars was far greater than what can be stored with 32 bit fixed point (16.16).<br><br>So, to convert a set of routines from floating point to fixed point, I follow the following tedious steps:<br><br>1: I identify the potential floating point vars I want to convert.<br><br>2: I identify every routine that modifies that var.<br><br>3: I use a logging function at every point that var is modified to record the min, max and smallest precision value that variable is assigned throughout the course of execution (usually allowing a full demo to run).<br><br>4: Based on the results of the logging I determine what fixed point precision (if any) to use for that particular variable.<br><br>5: I then have to study what operations occur between those variables. Some fixed point operations result in a loss of precision, others in a loss of range. I have to try and synchonize the fixed point precision so that multiplication and division operations don't result in overflow / underflow. I usually have a little precision to work with, but there are cases when I literaly did not have 1 single extra bit of precision to spare.<br><br>Dan East