summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2010-06-30 23:34:27 -0700
committerRuss Cox <rsc@golang.org>2010-06-30 23:34:27 -0700
commit8d6f97bb91a23b0dcde75e887e956d4d5b9b0e4b (patch)
tree19d0875707fb8df2cac52dca17a752afcfdf84ab
parentdfc0e76be949897032cfecc3e6a09518dc011ca9 (diff)
downloadgolang-8d6f97bb91a23b0dcde75e887e956d4d5b9b0e4b.tar.gz
test: override gcc bug when preparing complex divide tables
R=iant CC=golang-dev http://codereview.appspot.com/1666048
-rw-r--r--test/cmplxdivide.c25
-rw-r--r--test/cmplxdivide1.go13
2 files changed, 30 insertions, 8 deletions
diff --git a/test/cmplxdivide.c b/test/cmplxdivide.c
index 63473ba6c..b3c6055ed 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 58971691e..96ea704a3 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)},