diff options
author | Russ Cox <rsc@golang.org> | 2010-06-30 23:34:27 -0700 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2010-06-30 23:34:27 -0700 |
commit | 47c85ec97a483c9adde6ac00a0b9ef180a9472c2 (patch) | |
tree | e40053956566f390112c9811e14943d222fa16cf /test/cmplxdivide.c | |
parent | 93f614ff86a6a582c4458182af2f0238f108b122 (diff) | |
download | go-47c85ec97a483c9adde6ac00a0b9ef180a9472c2.tar.gz go-47c85ec97a483c9adde6ac00a0b9ef180a9472c2.zip |
test: override gcc bug when preparing complex divide tables
R=iant
CC=golang-dev
https://golang.org/cl/1666048
Diffstat (limited to 'test/cmplxdivide.c')
-rw-r--r-- | test/cmplxdivide.c | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/test/cmplxdivide.c b/test/cmplxdivide.c index 63473ba6cb..b3c6055ed2 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; |