Source file test/fixedbugs/issue7740.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 // 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 = math.Inf(1) // exact precision using rational arithmetic 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 } 36