2008-11-17 13:34:03 -07:00
|
|
|
// 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 strconv
|
|
|
|
|
2009-01-15 18:22:17 -07:00
|
|
|
export func Itoa64(i int64) string {
|
2008-11-17 13:34:03 -07:00
|
|
|
if i == 0 {
|
|
|
|
return "0"
|
|
|
|
}
|
2008-11-19 13:50:34 -07:00
|
|
|
|
2008-11-17 13:34:03 -07:00
|
|
|
neg := false; // negative
|
2008-11-19 13:50:34 -07:00
|
|
|
u := uint64(i);
|
2008-11-17 13:34:03 -07:00
|
|
|
if i < 0 {
|
|
|
|
neg = true;
|
|
|
|
u = -u;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Assemble decimal in reverse order.
|
|
|
|
var b [32]byte;
|
|
|
|
bp := len(b);
|
|
|
|
for ; u > 0; u /= 10 {
|
|
|
|
bp--;
|
|
|
|
b[bp] = byte(u%10) + '0'
|
|
|
|
}
|
|
|
|
if neg { // add sign
|
|
|
|
bp--;
|
|
|
|
b[bp] = '-'
|
|
|
|
}
|
2008-11-19 13:50:34 -07:00
|
|
|
|
2008-12-18 23:37:22 -07:00
|
|
|
return string(b[bp:len(b)])
|
2008-11-17 13:34:03 -07:00
|
|
|
}
|
|
|
|
|
2009-01-15 18:22:17 -07:00
|
|
|
export func Itoa(i int) string {
|
|
|
|
return Itoa64(int64(i));
|
2008-11-17 13:34:03 -07:00
|
|
|
}
|
|
|
|
|