diff options
Diffstat (limited to 'std/io.zig')
| -rw-r--r-- | std/io.zig | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/std/io.zig b/std/io.zig index be4320ad31..432600ee04 100644 --- a/std/io.zig +++ b/std/io.zig @@ -248,16 +248,19 @@ fn char_to_digit(c: u8) -> u8 { } } -pub fn buf_print_i64(out_buf: []u8, x: i64) -> isize { +pub fn buf_print_signed(T: type)(out_buf: []u8, x: T) -> isize { + const uint = @int_type(false, T.bit_count, false); if (x < 0) { out_buf[0] = '-'; - return 1 + buf_print_u64(out_buf[1...], u64(-(x + 1)) + 1); + return 1 + buf_print_unsigned(uint)(out_buf[1...], uint(-(x + 1)) + 1); } else { - return buf_print_u64(out_buf, u64(x)); + return buf_print_unsigned(uint)(out_buf, uint(x)); } } -pub fn buf_print_u64(out_buf: []u8, x: u64) -> isize { +pub const buf_print_i64 = buf_print_signed(i64); + +pub fn buf_print_unsigned(T: type)(out_buf: []u8, x: T) -> isize { var buf: [max_u64_base10_digits]u8 = undefined; var a = x; var index: isize = buf.len; @@ -278,6 +281,8 @@ pub fn buf_print_u64(out_buf: []u8, x: u64) -> isize { return len; } +pub const buf_print_u64 = buf_print_unsigned(u64); + pub fn buf_print_f64(out_buf: []u8, x: f64, decimals: isize) -> isize { const numExpBits = 11; const numRawSigBits = 52; // not including implicit 1 bit |
