From 47c85ec97a483c9adde6ac00a0b9ef180a9472c2 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 30 Jun 2010 23:34:27 -0700 Subject: [PATCH] test: override gcc bug when preparing complex divide tables R=iant CC=golang-dev https://golang.org/cl/1666048 --- test/cmplxdivide.c | 25 +++++++++++++++++++++++-- test/cmplxdivide1.go | 13 +++++++------ 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/test/cmplxdivide.c b/test/cmplxdivide.c index 63473ba6cbd..b3c6055ed23 100644 --- a/test/cmplxdivide.c +++ b/test/cmplxdivide.c @@ -35,7 +35,15 @@ fmt(double g) if(strcmp(p, "-0") == 0) strcpy(p, "negzero"); return p; -} +} + +int +iscnan(double complex d) +{ + return !isinf(creal(d)) && !isinf(cimag(d)) && (isnan(creal(d)) || isnan(cimag(d))); +} + +double complex zero; // attempt to hide zero division from gcc int main(void) @@ -54,7 +62,20 @@ main(void) n = f[i] + f[j]*I; d = f[k] + f[l]*I; q = n/d; - printf("\tTest{cmplx(%s, %s), cmplx(%s, %s), cmplx(%s, %s)},\n", fmt(creal(n)), fmt(cimag(n)), fmt(creal(d)), fmt(cimag(d)), fmt(creal(q)), fmt(cimag(q))); + + // BUG FIX. + // Gcc gets the wrong answer for NaN/0 unless both sides are NaN. + // That is, it treats (NaN+NaN*I)/0 = NaN+NaN*I (a complex NaN) + // but it then computes (1+NaN*I)/0 = Inf+NaN*I (a complex infinity). + // Since both numerators are complex NaNs, it seems that the + // results should agree in kind. Override the gcc computation in this case. + if(iscnan(n) && d == 0) + q = (NAN+NAN*I) / zero; + + printf("\tTest{cmplx(%s, %s), cmplx(%s, %s), cmplx(%s, %s)},\n", + fmt(creal(n)), fmt(cimag(n)), + fmt(creal(d)), fmt(cimag(d)), + fmt(creal(q)), fmt(cimag(q))); } printf("}\n"); return 0; diff --git a/test/cmplxdivide1.go b/test/cmplxdivide1.go index 58971691e54..96ea704a3e2 100644 --- a/test/cmplxdivide1.go +++ b/test/cmplxdivide1.go @@ -1,6 +1,7 @@ // # generated by cmplxdivide.c package main + var tests = []Test{ Test{cmplx(0, 0), cmplx(0, 0), cmplx(nan, nan)}, Test{cmplx(0, 0), cmplx(0, 1), cmplx(0, 0)}, @@ -541,7 +542,7 @@ var tests = []Test{ Test{cmplx(1, 2), cmplx(-inf, nan), cmplx(negzero, negzero)}, Test{cmplx(1, 2), cmplx(-inf, inf), cmplx(0, negzero)}, Test{cmplx(1, 2), cmplx(-inf, -inf), cmplx(negzero, negzero)}, - Test{cmplx(1, nan), cmplx(0, 0), cmplx(inf, nan)}, + Test{cmplx(1, nan), cmplx(0, 0), cmplx(nan, nan)}, Test{cmplx(1, nan), cmplx(0, 1), cmplx(nan, nan)}, Test{cmplx(1, nan), cmplx(0, -1), cmplx(nan, nan)}, Test{cmplx(1, nan), cmplx(0, 2), cmplx(nan, nan)}, @@ -884,7 +885,7 @@ var tests = []Test{ Test{cmplx(-1, 2), cmplx(-inf, nan), cmplx(0, negzero)}, Test{cmplx(-1, 2), cmplx(-inf, inf), cmplx(0, negzero)}, Test{cmplx(-1, 2), cmplx(-inf, -inf), cmplx(negzero, negzero)}, - Test{cmplx(-1, nan), cmplx(0, 0), cmplx(-inf, nan)}, + Test{cmplx(-1, nan), cmplx(0, 0), cmplx(nan, nan)}, Test{cmplx(-1, nan), cmplx(0, 1), cmplx(nan, nan)}, Test{cmplx(-1, nan), cmplx(0, -1), cmplx(nan, nan)}, Test{cmplx(-1, nan), cmplx(0, 2), cmplx(nan, nan)}, @@ -1227,7 +1228,7 @@ var tests = []Test{ Test{cmplx(2, 2), cmplx(-inf, nan), cmplx(negzero, negzero)}, Test{cmplx(2, 2), cmplx(-inf, inf), cmplx(0, negzero)}, Test{cmplx(2, 2), cmplx(-inf, -inf), cmplx(negzero, 0)}, - Test{cmplx(2, nan), cmplx(0, 0), cmplx(inf, nan)}, + Test{cmplx(2, nan), cmplx(0, 0), cmplx(nan, nan)}, Test{cmplx(2, nan), cmplx(0, 1), cmplx(nan, nan)}, Test{cmplx(2, nan), cmplx(0, -1), cmplx(nan, nan)}, Test{cmplx(2, nan), cmplx(0, 2), cmplx(nan, nan)}, @@ -1423,7 +1424,7 @@ var tests = []Test{ Test{cmplx(nan, 0), cmplx(-inf, nan), cmplx(nan, nan)}, Test{cmplx(nan, 0), cmplx(-inf, inf), cmplx(nan, nan)}, Test{cmplx(nan, 0), cmplx(-inf, -inf), cmplx(nan, nan)}, - Test{cmplx(nan, 1), cmplx(0, 0), cmplx(nan, inf)}, + Test{cmplx(nan, 1), cmplx(0, 0), cmplx(nan, nan)}, Test{cmplx(nan, 1), cmplx(0, 1), cmplx(nan, nan)}, Test{cmplx(nan, 1), cmplx(0, -1), cmplx(nan, nan)}, Test{cmplx(nan, 1), cmplx(0, 2), cmplx(nan, nan)}, @@ -1472,7 +1473,7 @@ var tests = []Test{ Test{cmplx(nan, 1), cmplx(-inf, nan), cmplx(nan, nan)}, Test{cmplx(nan, 1), cmplx(-inf, inf), cmplx(nan, nan)}, Test{cmplx(nan, 1), cmplx(-inf, -inf), cmplx(nan, nan)}, - Test{cmplx(nan, -1), cmplx(0, 0), cmplx(nan, -inf)}, + Test{cmplx(nan, -1), cmplx(0, 0), cmplx(nan, nan)}, Test{cmplx(nan, -1), cmplx(0, 1), cmplx(nan, nan)}, Test{cmplx(nan, -1), cmplx(0, -1), cmplx(nan, nan)}, Test{cmplx(nan, -1), cmplx(0, 2), cmplx(nan, nan)}, @@ -1521,7 +1522,7 @@ var tests = []Test{ Test{cmplx(nan, -1), cmplx(-inf, nan), cmplx(nan, nan)}, Test{cmplx(nan, -1), cmplx(-inf, inf), cmplx(nan, nan)}, Test{cmplx(nan, -1), cmplx(-inf, -inf), cmplx(nan, nan)}, - Test{cmplx(nan, 2), cmplx(0, 0), cmplx(nan, inf)}, + Test{cmplx(nan, 2), cmplx(0, 0), cmplx(nan, nan)}, Test{cmplx(nan, 2), cmplx(0, 1), cmplx(nan, nan)}, Test{cmplx(nan, 2), cmplx(0, -1), cmplx(nan, nan)}, Test{cmplx(nan, 2), cmplx(0, 2), cmplx(nan, nan)},