diff options
author | Russ Cox <rsc@golang.org> | 2008-11-17 12:33:49 -0800 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2008-11-17 12:33:49 -0800 |
commit | c86382bcfc0560e6a756cd925f851869eb5a96d5 (patch) | |
tree | 58c6f872b401224f286e6b4623c6c786e37a8614 | |
parent | 776365bbdbfe419e36168315f8fef33173d31de8 (diff) | |
download | golang-c86382bcfc0560e6a756cd925f851869eb5a96d5.tar.gz |
floating point constant errors in 6g
R=r
OCL=19379
CL=19379
-rw-r--r-- | test/bugs/bug120.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/test/bugs/bug120.go b/test/bugs/bug120.go new file mode 100644 index 000000000..58639c792 --- /dev/null +++ b/test/bugs/bug120.go @@ -0,0 +1,39 @@ +// $G $D/$F.go && $L $F.$A && ./$A.out || echo BUG: bug120 + +// Copyright 2009 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. + +package main + +import "strconv"; + +type Test struct { + f float64; + in string; + out string; +} + +var tests = []Test { + Test{ 123.5, "123.5", "123.5" }, + Test{ 456.7, "456.7", "456.7" }, + Test{ 1e23+8.5e6, "1e23+8.5e6", "1.0000000000000001e+23" }, + Test{ 100000000000000008388608, "100000000000000008388608", "1.0000000000000001e+23" }, + Test{ 1e23+8.388608e6, "1e23+8.388608e6", "1.0000000000000001e+23" }, + Test{ 1e23+8.388609e6, "1e23+8.388609e6", "1.0000000000000001e+23" }, +} + +func main() { + ok := true; + for i := 0; i < len(tests); i++ { + t := tests[i]; + v := strconv.ftoa64(t.f, 'g', -1); + if v != t.out { + println("Bad float64 const:", t.in, "want", t.out, "got", v); + ok = false; + } + } + if !ok { + panicln("bug120"); + } +} |