Robert Griesemer | 5bb89eb | 2015-03-20 16:59:08 -0700 | [diff] [blame] | 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": |
Robert Griesemer | a51d5f2 | 2015-04-02 16:34:48 -0700 | [diff] [blame] | 24 | prec = 512 |
Robert Griesemer | 5bb89eb | 2015-03-20 16:59:08 -0700 | [diff] [blame] | 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 | } |