1
0
mirror of https://github.com/golang/go synced 2024-11-25 15:57:57 -07:00

- a couple of fixes for integer.go

- added pkg dir

SVN=124991
This commit is contained in:
Robert Griesemer 2008-06-26 16:15:43 -07:00
parent bcfd31f0e9
commit 433ac8e57b
2 changed files with 27 additions and 3 deletions

View File

@ -10,7 +10,9 @@ type Box struct {};
var m map[string] *Box;
func main() {
m["foo"] = nil;
s := "foo";
var x *Box = nil;
m[s] = x;
}
/*

View File

@ -415,7 +415,7 @@ func copy(x Value) Value {
z := alloc(xl + 1); // add space for one extra digit
for i := 0; i < xl; i++ { z[i + H] = x[i + H]; }
set_len(z, xl);
set_len(z, int(x[0])); // don't loose sign!
return z;
}
@ -569,7 +569,14 @@ func (x Integer) xor (y Integer) Integer {
// Comparisons
func (x Integer) cmp (y Integer) int {
return 0;
// do better then this
d := x.sub(y);
switch {
case sign(d.val): return -1;
case zero(d.val): return 0;
default : return +1;
}
CHECK(false); // unreachable
}
@ -616,3 +623,18 @@ func (x Integer) ToString() string {
return tostring(x.val);
}
func (x Integer) ToInt() int {
v := x.val;
if len_(v) <= 1 {
if zero(v) {
return 0;
}
i := int(v[0 + H]);
if sign(v) {
i = -i; // incorrect for smallest int
}
return i;
}
panic "integer too large";
}