]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: check for signed zero in printfloat
authorCarl Shapiro <cshapiro@google.com>
Tue, 10 Dec 2013 01:51:30 +0000 (17:51 -0800)
committerCarl Shapiro <cshapiro@google.com>
Tue, 10 Dec 2013 01:51:30 +0000 (17:51 -0800)
Fixes #6899

R=golang-dev, r, cshapiro, iant, rsc
CC=golang-dev
https://golang.org/cl/38120043

src/pkg/runtime/print.c
test/fixedbugs/issue6899.go [new file with mode: 0644]
test/fixedbugs/issue6899.out [new file with mode: 0644]

index 8de3ae4fa19a73bf01693e6ab6b0dd93fd0ef21b..edb5a1c2ee02db3fa967f69c57289b1566fafaf8 100644 (file)
@@ -236,7 +236,10 @@ runtime·printfloat(float64 v)
        n = 7;  // digits printed
        e = 0;  // exp
        s = 0;  // sign
-       if(v != 0) {
+       if(v == 0) {
+               if(1/v == runtime·neginf)
+                       s = 1;
+       } else {
                // sign
                if(v < 0) {
                        v = -v;
diff --git a/test/fixedbugs/issue6899.go b/test/fixedbugs/issue6899.go
new file mode 100644 (file)
index 0000000..a693bf2
--- /dev/null
@@ -0,0 +1,13 @@
+// cmpout
+
+// Copyright 2013 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 "math"
+
+func main() {
+       println(math.Copysign(0, -1))
+}
diff --git a/test/fixedbugs/issue6899.out b/test/fixedbugs/issue6899.out
new file mode 100644 (file)
index 0000000..e2375f0
--- /dev/null
@@ -0,0 +1 @@
+-0.000000e+000