Actually do a test for triangle.r.

If the kahan triangle area method breaks, I did something wrong with qfcc's
handling of parentheses (ie, floating point math is not truly associative).
This commit is contained in:
Bill Currie 2018-08-23 20:50:06 +09:00
parent 1b9149ef31
commit b37b0180cb
2 changed files with 10 additions and 9 deletions

View file

@ -153,7 +153,7 @@ triangle_obj=$(triangle_dat_SOURCES:.r=.qfo)
triangle.dat$(EXEEXT): $(triangle_obj) $(QFCC_DEP)
$(QFCC) $(QCFLAGS) -o $@ $(triangle_obj)
triangle.run: Makefile build-run
$(srcdir)/build-run $@ 1 2 3
$(srcdir)/build-run $@ 100000 100000 1.00005 50002.4961
vecinit_dat_SOURCES=vecinit.r
vecinit_obj=$(vecinit_dat_SOURCES:.r=.qfo)

View file

@ -16,17 +16,18 @@ kahan (float a, float b, float c)
if (a < b) { t = a; a = b; b = t; }
if (b < c) { t = b; b = c; c = t; }
if (a < b) { t = a; a = b; b = t; }
printf ("%f %f %f\n", a, b, c);
return sqrt ((a+(b+c))*(c-(a-b))*(c+(a-b))*(a+(b-c)))/4;
return sqrt ((a + (b + c))*(c - (a - b))*(c + (a - b))*(a + (b - c)))/4;
}
int
main (int argc, string *argv)
{
float a = stof(argv[1]);
float b = stof(argv[2]);
float c = stof(argv[3]);
printf ("%.9g %.9g %.9g\n", a, b, c);
printf ("%.9g %.9g\n", heron (a, b, c), kahan (a, b, c));
return 0;
float a = stof (argv[1]);
float b = stof (argv[2]);
float c = stof (argv[3]);
float expt = stof (argv[4]);
float h = heron (a, b, c);
float k = kahan (a, b, c);
printf ("%.9g %.9g %d\n", h, k, k == expt);
return k != expt;
}