diff --git a/vlib/builtin/int.v b/vlib/builtin/int.v index 1dcbb21658..538971818e 100644 --- a/vlib/builtin/int.v +++ b/vlib/builtin/int.v @@ -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++] diff --git a/vlib/builtin/int_test.v b/vlib/builtin/int_test.v index cdfa436300..8650bc747f 100644 --- a/vlib/builtin/int_test.v +++ b/vlib/builtin/int_test.v @@ -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'