Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Diff tool that ignores floating-point formats (but not values) in text?

I'm looking for a diff tool that can also compare floating point values (within some tolerance) in text files. This is in addition to typical text-comparison diff functions, with options to ignore whitespace, ignore case, etc. A GUI (or full-screen console UI) is okay, but I'd really prefer a stream-oriented (stdin/stdout) tool.

Here's an extremely simple example that characterizes the ideal tool. There are 2 versions of foo.c:

foo_v1.c:

#include <stdio.h>

#define PI        3.14159265359
#define E_CUBED   20.0855
#define HALF_PHI  0.809f
#define C_SQUARED 89875517873681764.0L

const double AVO = 6.022e23; /* Avocado number */

int main()
{
  printf("%g %g %g %Lg %g\n", PI, E_CUBED, HALF_PHI, C_SQUARED, AVO);
  return 0;
}

foo_v2.c:

#include <stdio.h>

#define PI        3.14159265358979
#define E_CUBED   2.00855e+1
#define HALF_PHI  8.09e-1f
#define C_SQUARED 8.9875517873681764e18L

const double AVO = 6.022e23; /* Avogadro number */

int main()
{
  printf("%g %g %g %Lg %g\n", PI, E_CUBED, HALF_PHI, C_SQUARED, AVO);
  return 0;
}

And here's the diff output I'd expect:

$ diff --floats=byvalue --tolerance=1e-9 foo_v1.c foo_v2.c
6c6
< #define C_SQUARED 89875517873681764.0L
---
> #define C_SQUARED 8.9875517873681764e18L
8c8
< const double AVO = 6.022e23; /* Avocado number */
---
> const double AVO = 6.022e23; /* Avogadro number */

The second diff (line 8) is the usual text difference; the first diff (line 6) is due to the numbers being outside of the specified tolerance. (The exponent should be 16, not 18, so it's off by 100.0X).

Note that none of the other floating point changes show up as diffs—even though they are text changes, the floating point values do not change beyond the specified tolerance.

Is there a diff tool that can do this?

If not, is there something close, that's open-source?

like image 499
system PAUSE Avatar asked Sep 15 '09 16:09

system PAUSE


2 Answers

The one that I found recently:

http://www.nongnu.org/numdiff/

It's very intuitive.

like image 68
mfolusiak Avatar answered Nov 17 '22 00:11

mfolusiak


There is this one, which looks very interesting. I'm trying to have it working on my AIX, so I haven't seem it in action yet, but I believe this is what you (and I :-) need

http://hpux.connect.org.uk/hppd/hpux/Text/spiff-1.0/

like image 41
Davide Avatar answered Nov 17 '22 01:11

Davide