diff --git a/vlib/strconv/format_mem.c.v b/vlib/strconv/format_mem.c.v index 89ae767ab7a216..ea204268299172 100644 --- a/vlib/strconv/format_mem.c.v +++ b/vlib/strconv/format_mem.c.v @@ -34,8 +34,6 @@ pub fn format_str_sb(s string, p BF_param, mut sb strings.Builder) { } } -const max_size_f64_char = 32 // the f64 max representation is -36,028,797,018,963,968e1023, 21 chars, 32 is faster for the memory manger - // digit pairs in reverse order const digit_pairs = '00102030405060708090011121314151617181910212223242526272829203132333435363738393041424344454647484940515253545556575859506162636465666768696071727374757677787970818283848586878889809192939495969798999' @@ -328,8 +326,8 @@ pub fn format_fl(f f64, p BF_param) string { tmp.free() } - mut buf := [max_size_f64_char]u8{} // write temp float buffer in stack - mut out := [max_size_f64_char]u8{} // out buffer + mut buf := []u8{len: p.len0 + 32} // write temp float buffer + mut out := []u8{len: p.len0 + 32} // out buffer mut buf_i := 0 // index temporary string mut out_i := 0 // index output string @@ -399,8 +397,8 @@ pub fn format_es(f f64, p BF_param) string { tmp.free() } - mut buf := [max_size_f64_char]u8{} // write temp float buffer in stack - mut out := [max_size_f64_char]u8{} // out buffer + mut buf := []u8{len: p.len0 + 32} // write temp float buffer + mut out := []u8{len: p.len0 + 32} // out buffer mut buf_i := 0 // index temporary string mut out_i := 0 // index output string diff --git a/vlib/strconv/format_mem.js.v b/vlib/strconv/format_mem.js.v index 0fe57d60d4c91d..35ca8b27f4ee71 100644 --- a/vlib/strconv/format_mem.js.v +++ b/vlib/strconv/format_mem.js.v @@ -30,8 +30,6 @@ pub fn format_str_sb(s string, p BF_param, mut sb strings.Builder) { } } -const max_size_f64_char = 32 // the f64 max representation is -36,028,797,018,963,968e1023, 21 chars, 32 is faster for the memory manger - // digit pairs in reverse order const digit_pairs = '00102030405060708090011121314151617181910212223242526272829203132333435363738393041424344454647484940515253545556575859506162636465666768696071727374757677787970818283848586878889809192939495969798999' diff --git a/vlib/v/slow_tests/inout/printing_interpolating_float.out b/vlib/v/slow_tests/inout/printing_interpolating_float.out new file mode 100644 index 00000000000000..3e36bdefedaccf --- /dev/null +++ b/vlib/v/slow_tests/inout/printing_interpolating_float.out @@ -0,0 +1,4 @@ + 0.10 + 0.10 + 0.10 + 0.100 diff --git a/vlib/v/slow_tests/inout/printing_interpolating_float.vv b/vlib/v/slow_tests/inout/printing_interpolating_float.vv new file mode 100644 index 00000000000000..3939c0e5d947dc --- /dev/null +++ b/vlib/v/slow_tests/inout/printing_interpolating_float.vv @@ -0,0 +1,7 @@ +fn main() { + n := 0.1 + println('${n:36.2f}') + println('${n:37.2f}') + println('${n:38.2f}') + println('${n:70.3f}') +}