summaryrefslogtreecommitdiff
path: root/test/cmplxdivide.c
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
commite8ac5de79dd35da9fc28f8587739902ad684c448 (patch)
tree19d0875707fb8df2cac52dca17a752afcfdf84ab /test/cmplxdivide.c
parent2f40b6f173baeb8444cf5dd8a060f87b295a1b6e (diff)
downloadgo-e8ac5de79dd35da9fc28f8587739902ad684c448.tar.gz
test: override gcc bug when preparing complex divide tables
R=iant CC=golang-dev http://codereview.appspot.com/1666048
Diffstat (limited to 'test/cmplxdivide.c')
-rw-r--r--test/cmplxdivide.c25
1 files changed, 23 insertions, 2 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;