Wednesday, March 5, 2008

Floating point inaccuracies

My current project in work involves resolving some differences between output under different platforms (32bit vs. 64bit vs. VC6 compiler vs. VS2005 compiler, etc.). Sometimes the floating point errors are difficult to trace. Many times, they are not particularly intuitive. I think that the average programmer probably doesn't know why calculating (x+y)*(x-y) is preferred over (x^2 - y^2).

Here's a spec for a useful tool that deals with these issues:

Input:
  1. A function that returns a floating point value.
  2. A description of the inputs (ranges, precision) to the function.

Output:
  1. The worst case, best case and average error introduced by the floating point operations in the program (Error is provided as a relative error and ulps (units in the last place)).

Operational description:
  1. Compile the input program using a floating point and fixed point data type for the operands involved.
  2. Execute the program using the variety of input parameters specified.
  3. Record the results from both versions of the software and compare.
  4. Provide the summary statistics as output.

Required tools:
  1. Some sort of fixed point math library.
  2. Perhaps some sort of parser for the programming language desired (I dunno).