diff options
author | Robert Griesemer <gri@golang.org> | 2009-05-27 09:57:44 -0700 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2009-05-27 09:57:44 -0700 |
commit | b850a669213485b783e65c6ac75b50047a5d2d0a (patch) | |
tree | bc9208eb8981db2a729c9513edf3174dadff1c65 /test/bugs | |
parent | 293f4c99e036df2810a4e1f3a3a87180eff110bb (diff) | |
download | go-b850a669213485b783e65c6ac75b50047a5d2d0a.tar.gz |
floating point bug
R=rsc
DELTA=35 (35 added, 0 deleted, 0 changed)
OCL=29442
CL=29444
Diffstat (limited to 'test/bugs')
-rw-r--r-- | test/bugs/bug154.go | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/test/bugs/bug154.go b/test/bugs/bug154.go new file mode 100644 index 000000000..60bcb8e50 --- /dev/null +++ b/test/bugs/bug154.go @@ -0,0 +1,32 @@ +// $G $D/$F.go && $L $F.$A && ./$A.out || echo BUG: should not panic + +// 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 "fmt" + +func f0() string { + const f = 3.141592; + return fmt.Sprintf("%v", float64(f)); +} + + +func f1() string { + const f = 3.141592; + _ := float64(float32(f)); // appears to change the precision of f + return fmt.Sprintf("%v", float64(f)); +} + + +func main() { + r0 := f0(); + r1 := f1(); + if r0 != r1 { + println("r0 =", r0); + println("r1 =", r1); + panic("r0 and r1 should be the same"); + } +} |