builtin: fix min value for int_str (#6411)
parent
ffc8cf3925
commit
c1f04d8c72
|
@ -58,7 +58,7 @@ const(
|
||||||
// This implementation is the quickest with gcc -O2
|
// This implementation is the quickest with gcc -O2
|
||||||
[inline]
|
[inline]
|
||||||
pub fn (nn int) str_l(max int) string {
|
pub fn (nn int) str_l(max int) string {
|
||||||
mut n := nn
|
mut n := i64(nn)
|
||||||
mut d := 0
|
mut d := 0
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
return '0'
|
return '0'
|
||||||
|
@ -76,8 +76,8 @@ pub fn (nn int) str_l(max int) string {
|
||||||
buf[index--] = `\0`
|
buf[index--] = `\0`
|
||||||
}
|
}
|
||||||
for n > 0 {
|
for n > 0 {
|
||||||
n1 := n / 100
|
n1 := int(n / 100)
|
||||||
d = ((n - (n1 * 100)) << 1)
|
d = ((int(n) - (n1 * 100)) << 1)
|
||||||
n = n1
|
n = n1
|
||||||
unsafe {
|
unsafe {
|
||||||
buf[index--] = digit_pairs.str[d++]
|
buf[index--] = digit_pairs.str[d++]
|
||||||
|
|
|
@ -18,6 +18,9 @@ fn test_str_methods() {
|
||||||
assert i16(-1).str() == '-1'
|
assert i16(-1).str() == '-1'
|
||||||
assert int(1).str() == '1'
|
assert int(1).str() == '1'
|
||||||
assert int(-1).str() == '-1'
|
assert int(-1).str() == '-1'
|
||||||
|
assert int(2147483647).str() == '2147483647'
|
||||||
|
assert int(2147483648).str() == '-2147483648'
|
||||||
|
assert int(-2147483648).str() == '-2147483648'
|
||||||
assert i64(1).str() == '1'
|
assert i64(1).str() == '1'
|
||||||
assert i64(-1).str() == '-1'
|
assert i64(-1).str() == '-1'
|
||||||
// assert byte(1).str() == '1'
|
// assert byte(1).str() == '1'
|
||||||
|
|
Loading…
Reference in New Issue