1
0
mirror of https://github.com/golang/go synced 2024-10-04 10:21:21 -06:00
go/src/lib/strconv/itoa.go

38 lines
589 B
Go
Raw Normal View History

// 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-20 15:40:40 -07:00
func Itoa64(i int64) string {
if i == 0 {
return "0"
}
neg := false; // negative
u := uint64(i);
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] = '-'
}
return string(b[bp:len(b)])
}
2009-01-20 15:40:40 -07:00
func Itoa(i int) string {
return Itoa64(int64(i));
}