1
0
mirror of https://github.com/golang/go synced 2024-11-14 23:40:35 -07:00
go/test/fixedbugs/issue7740.go
Robert Griesemer a51d5f27e8 cmd/internal/gc: use 512 bits (rather than 464) for multi-precision arithmetic
The original implementation used 16 int "words" but only 29 bits per word
for a total of 16*29 = 464 bits, with a space consumption of 16*64 = 1024
bits on a 64 bit machine. Switching to 512 bits increases precision while
still using (in the worst case) half the amount of memory per mp value on
a 64 bit machine.

Also: Decreased permitted number of least-significant mantissa bits which
may be incorrect when considering if a precise floating-point constant is
an integer from 29 to 16 bits.

Change-Id: Iee9287056f0e9aa4f06ceac0724ff4674f710c53
Reviewed-on: https://go-review.googlesource.com/8429
Reviewed-by: Russ Cox <rsc@golang.org>
2015-04-03 17:13:07 +00:00

36 lines
683 B
Go

// run
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// This test computes the precision of the compiler's internal multiprecision floats.
package main
import (
"fmt"
"math"
"runtime"
)
const ulp = (1.0 + (2.0 / 3.0)) - (5.0 / 3.0)
func main() {
// adjust precision depending on compiler
var prec float64
switch runtime.Compiler {
case "gc":
prec = 512
case "gccgo":
prec = 256
default:
// unknown compiler
return
}
p := 1 - math.Log(math.Abs(ulp))/math.Log(2)
if math.Abs(p-prec) > 1e-10 {
fmt.Printf("BUG: got %g; want %g\n", p, prec)
}
}