]> Cypherpunks repositories - gostls13.git/commitdiff
fix printing of -(1<<63)
authorRuss Cox <rsc@golang.org>
Wed, 17 Sep 2008 21:08:52 +0000 (14:08 -0700)
committerRuss Cox <rsc@golang.org>
Wed, 17 Sep 2008 21:08:52 +0000 (14:08 -0700)
R=r
OCL=15441
CL=15445

src/runtime/print.c
test/golden.out
test/printbig.go [new file with mode: 0644]

index 8236f04b4af287ef47d0f3745aca77c6da2625a5..726665bb760e8b78d69b3c7434733c92ce9a0085 100644 (file)
@@ -112,15 +112,16 @@ void
 sys·printint(int64 v)
 {
        byte buf[100];
-       int32 i, s;
+       int32 i, s, big;
 
+       big = 0;
        s = 0;
        if(v < 0) {
                v = -v;
                s = 1;
                if(v < 0) {
-                       sys·write(1, (byte*)"-oo", 3);
-                       return;
+                       big = 1;
+                       v--;
                }
        }
 
@@ -130,10 +131,13 @@ sys·printint(int64 v)
                        break;
                v = v/10;
        }
-       if(s) {
+       if(s){
                i--;
                buf[i] = '-';
        }
+       if(big){
+               buf[nelem(buf)-1]++;
+       }
        sys·write(1, buf+i, nelem(buf)-i);
 }
 
index e39abee1fbf3bfe3584b84b9f73bbb558a1c105d..9689f1cb73464b16388210969d36af6ac65df296 100644 (file)
@@ -1,30 +1,4 @@
 
-=========== ./bufiolib.go
-throw: index out of range
-SIGSEGV: segmentation violation
-Faulting address: 0x0
-pc: 0x11c43
-
-0x11c43?zi
-       throw(98060, 0, 235528, ...)
-       throw(0x17f0c, 0x39808, 0x5e2e, ...)
-0x11b97?zi
-       sys·throwindex(235528, 0, 0, ...)
-       sys·throwindex(0x39808, 0x0, 0x1, ...)
-0x5e2e?zi
-       bufio·BufRead_ReadLineString(235312, 0, 65546, ...)
-       bufio·BufRead_ReadLineString(0x39730, 0x1000a, 0x39758, ...)
-0x1cb8?zi
-       main·ReadLines(235312, 0, 235304, ...)
-       main·ReadLines(0x39730, 0x39728, 0x1, ...)
-0x2bb5?zi
-       main·TestBufRead(85470, 0, 1, ...)
-       main·TestBufRead(0x14dde, 0x1, 0x7fff5fbff268, ...)
-0x3830?zi
-       main·main(1, 0, 1606414952, ...)
-       main·main(0x1, 0x7fff5fbff268, 0x0, ...)
-
-
 =========== ./func1.go
 func1.go:12: var a redeclared in this block
      previous declaration at func1.go:12
@@ -48,6 +22,10 @@ skipping increment test until bug060 is fixed
 9! = 362880
 10! = 3628800
 
+=========== ./printbig.go
+-9223372036854775808
+9223372036854775807
+
 =========== ./turing.go
 Hello World!
 
diff --git a/test/printbig.go b/test/printbig.go
new file mode 100644 (file)
index 0000000..5ec95b9
--- /dev/null
@@ -0,0 +1,12 @@
+// $G $F.go && $L $F.$A && ./$A.out
+
+// 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
+
+func main() {
+       print(-(1<<63), "\n");
+       print((1<<63)-1, "\n")
+}