Source file test/fixedbugs/issue6866.go

     1  // run
     2  
     3  // Copyright 2015 The Go Authors. All rights reserved.
     4  // Use of this source code is governed by a BSD-style
     5  // license that can be found in the LICENSE file.
     6  
     7  // WARNING: GENERATED FILE - DO NOT MODIFY MANUALLY!
     8  // (To generate, in go/types directory: go test -run=Hilbert -H=2 -out="h2.src")
     9  
    10  // This program tests arbitrary precision constant arithmetic
    11  // by generating the constant elements of a Hilbert matrix H,
    12  // its inverse I, and the product P = H*I. The product should
    13  // be the identity matrix.
    14  package main
    15  
    16  func main() {
    17  	if !ok {
    18  		print()
    19  		return
    20  	}
    21  }
    22  
    23  // Hilbert matrix, n = 2
    24  const (
    25  	h0_0, h0_1 = 1.0 / (iota + 1), 1.0 / (iota + 2)
    26  	h1_0, h1_1
    27  )
    28  
    29  // Inverse Hilbert matrix
    30  const (
    31  	i0_0 = +1 * b2_1 * b2_1 * b0_0 * b0_0
    32  	i0_1 = -2 * b2_0 * b3_1 * b1_0 * b1_0
    33  
    34  	i1_0 = -2 * b3_1 * b2_0 * b1_1 * b1_1
    35  	i1_1 = +3 * b3_0 * b3_0 * b2_1 * b2_1
    36  )
    37  
    38  // Product matrix
    39  const (
    40  	p0_0 = h0_0*i0_0 + h0_1*i1_0
    41  	p0_1 = h0_0*i0_1 + h0_1*i1_1
    42  
    43  	p1_0 = h1_0*i0_0 + h1_1*i1_0
    44  	p1_1 = h1_0*i0_1 + h1_1*i1_1
    45  )
    46  
    47  // Verify that product is identity matrix
    48  const ok = p0_0 == 1 && p0_1 == 0 &&
    49  	p1_0 == 0 && p1_1 == 1 &&
    50  	true
    51  
    52  func print() {
    53  	println(p0_0, p0_1)
    54  	println(p1_0, p1_1)
    55  }
    56  
    57  // Binomials
    58  const (
    59  	b0_0 = f0 / (f0 * f0)
    60  
    61  	b1_0 = f1 / (f0 * f1)
    62  	b1_1 = f1 / (f1 * f0)
    63  
    64  	b2_0 = f2 / (f0 * f2)
    65  	b2_1 = f2 / (f1 * f1)
    66  	b2_2 = f2 / (f2 * f0)
    67  
    68  	b3_0 = f3 / (f0 * f3)
    69  	b3_1 = f3 / (f1 * f2)
    70  	b3_2 = f3 / (f2 * f1)
    71  	b3_3 = f3 / (f3 * f0)
    72  )
    73  
    74  // Factorials
    75  const (
    76  	f0 = 1
    77  	f1 = 1
    78  	f2 = f1 * 2
    79  	f3 = f2 * 3
    80  )
    81  

View as plain text