From c1f04d8c72299c6048f97af1facbb4bf22241adf Mon Sep 17 00:00:00 2001 From: Henrixounez <30901439+Henrixounez@users.noreply.github.com> Date: Fri, 18 Sep 2020 11:56:16 +0200 Subject: [PATCH] builtin: fix min value for int_str (#6411) --- vlib/builtin/int.v | 6 +++--- vlib/builtin/int_test.v | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) 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'