blob: 8f1afe86dae5ed1258190fdb1308522de238d2c7 [file] [log] [blame]
Robert Griesemer5bb89eb2015-03-20 16:59:08 -07001// 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
9package main
10
11import (
12 "fmt"
13 "math"
14 "runtime"
15)
16
17const ulp = (1.0 + (2.0 / 3.0)) - (5.0 / 3.0)
18
19func main() {
20 // adjust precision depending on compiler
21 var prec float64
22 switch runtime.Compiler {
23 case "gc":
Robert Griesemera51d5f22015-04-02 16:34:48 -070024 prec = 512
Robert Griesemer5bb89eb2015-03-20 16:59:08 -070025 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}