tools/go
Robert Griesemer 14cf5b0a28 go.tools/go/types: fun with Hilbert: a const arithmetic test
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
2013-12-03 13:36:57 -08:00
..
exact go.tools/go/exact: some factoring, more tests 2013-11-12 12:45:43 -08:00
gcimporter go.tools/go/gcimporter: ImportData has no need for *bufio.Reader, can get just io.Reader. 2013-11-24 12:48:45 -08:00
types go.tools/go/types: fun with Hilbert: a const arithmetic test 2013-12-03 13:36:57 -08:00
vcs go.tools/vcs: allow compilation with go 1.0 2013-10-04 11:46:57 +10:00