new2 new2

ndiff --- compare putatively similar files, ignoring small numeric differences

Last update: Tue Apr 23 08:39:02 2002
Last update: Fri Nov 12 15:50:09 2004

Suppose that you have just run the same numerical program in two different environments, perhaps different compilers on the same system, or on different CPU architectures or operating systems. You run diff on the two program output text files, but there are thousands of differences reported. Is the program behaving acceptably, or are there real errors that you must deal with, perhaps due to architectural assumptions in your code, or to numerical instabilities in your algorithms, or errors in compiler-generated code, or errors or inaccuracies in run-time libraries?

ndiff is a very useful tool for solving problems like that. Simply put, it assumes that you have two text files containing numerical values, and the two files are expected to be identical, or at least numerically similar. ndiff allows you to specify absolute and/or relative error tolerances for differences between numerical values in the two files, and then reports only the lines with values exceeding those tolerances. It also tells you by how much they differ.

To make this clearer, here is a simple example. First, we choose a coarse error relative tolerance, to reduce ndiff 's output to show the worst-case error detected:

% ndiff --relative-error 1.0e-3 test019.txt.1 test019.txt.2
### Maximum relative error in matching lines = 8.64e-51 at line 129 field 4

We now know that the files match very closely. To see line differences, we run ndiff again with a tolerance somewhat below the worst-case error reported:

% ndiff --relative-error 6.0e-51 test019.txt.1 test019.txt.2
< 1     39.0    0           1.52783004033758092947808545583545158085218122489240e+40
--- field 4     relative error 6.54e-51
> 1     39.0    0           1.52783004033758092947808545583545158085218122489241e+40
< 1     53.0    0          -1.15716272274907744883182951512406131215103585713240e+62
--- field 4     relative error 8.64e-51
> 1     53.0    0          -1.15716272274907744883182951512406131215103585713241e+62
< 1     70.5    0          -1.34783696863714343135850192081091166833218144876440e+90
--- field 4     relative error 7.41e-51
> 1     70.5    0          -1.34783696863714343135850192081091166833218144876441e+90
### Maximum relative error in matching lines = 5.72e-51 at line 57 field 4

ndiff has found three cases of numerical relative errors above the requested tolerance, and we can see that the fields differ in the last decimal place. It also reports that, of the differences not shown, the worst-case error is now 5.72e-51.

ndiff has many more features: they are described in its manual pages.

The source distributions are available in several archive formats:

For historical purposes, earlier versions remain available as well: