This test generates a program that declares the constant elements of an n*n Hilbert matrix, its inverse, and the constant elements of the explicit product of the two. The product should be the identity matrix; that check is also expressed as a constant expression. Type-checking verifies that the product is indeed the identity matrix by asserting the result of the identity check (using the assert built-in which is available for type-check tests). The test is run for n = 5. Other values can be tested via the -H flag, say: go test -run=Hilbert -H=100 The generated program can be written to a file for testing the constant arithmetic of a compiler: go test -out=test.go Because of the mathematically precise constant arithmetic of go/types, this test should always succeed and is only limited by the size of the matrix. It does run successfully from n = 0 to values larger than 100. The Hilbert matrix is famous for being ill-conditioned and thus exposes arithmetic imprecision very quickly. The gc compiler only produces a correct result for n = 0 (trivially), and n = 1 at the moment. R=adonovan, rsc CC=golang-dev https://golang.org/cl/35840043 |
||
|---|---|---|
| .. | ||
| exact | ||
| gcimporter | ||
| types | ||
| vcs | ||