modernc.org/gc@v1.0.1-0.20240304020402-f0dba7c97c2b/testdata/errchk/test/fixedbugs/issue7740.go (about)

     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  // This test computes the precision of the compiler's internal multiprecision floats.
     8  
     9  package main
    10  
    11  import (
    12  	"fmt"
    13  	"math"
    14  	"runtime"
    15  )
    16  
    17  const ulp = (1.0 + (2.0 / 3.0)) - (5.0 / 3.0)
    18  
    19  func main() {
    20  	// adjust precision depending on compiler
    21  	var prec float64
    22  	switch runtime.Compiler {
    23  	case "gc":
    24  		prec = 512
    25  	case "gccgo":
    26  		prec = 256
    27  	default:
    28  		// unknown compiler
    29  		return
    30  	}
    31  	p := 1 - math.Log(math.Abs(ulp))/math.Log(2)
    32  	if math.Abs(p-prec) > 1e-10 {
    33  		fmt.Printf("BUG: got %g; want %g\n", p, prec)
    34  	}
    35  }