1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

builtin: fix min value for int_str (#6411)

This commit is contained in:
Henrixounez
2020-09-18 11:56:16 +02:00
committed by GitHub
parent ffc8cf3925
commit c1f04d8c72
2 changed files with 6 additions and 3 deletions

View File

@@ -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++]

View File

@@ -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'