builtin: fix min value for int_str (#6411)

pull/6416/head
Henrixounez 2020-09-18 11:56:16 +02:00 committed by GitHub
parent ffc8cf3925
commit c1f04d8c72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 3 deletions

View File

@ -58,7 +58,7 @@ const(
// This implementation is the quickest with gcc -O2
[inline]
pub fn (nn int) str_l(max int) string {
mut n := nn
mut n := i64(nn)
mut d := 0
if n == 0 {
return '0'
@ -76,8 +76,8 @@ pub fn (nn int) str_l(max int) string {
buf[index--] = `\0`
}
for n > 0 {
n1 := n / 100
d = ((n - (n1 * 100)) << 1)
n1 := int(n / 100)
d = ((int(n) - (n1 * 100)) << 1)
n = n1
unsafe {
buf[index--] = digit_pairs.str[d++]

View File

@ -18,6 +18,9 @@ fn test_str_methods() {
assert i16(-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 byte(1).str() == '1'