| ... | ... | @@ -248,16 +248,19 @@ fn char_to_digit(c: u8) -> u8 { |
| 248 | 248 | } |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | | pub fn buf_print_i64(out_buf: []u8, x: i64) -> isize { |
| 251 | pub fn buf_print_signed(T: type)(out_buf: []u8, x: T) -> isize { |
| 252 | const uint = @int_type(false, T.bit_count, false); |
| 252 | 253 | if (x < 0) { |
| 253 | 254 | out_buf[0] = '-'; |
| 254 | | return 1 + buf_print_u64(out_buf[1...], u64(-(x + 1)) + 1); |
| 255 | return 1 + buf_print_unsigned(uint)(out_buf[1...], uint(-(x + 1)) + 1); |
| 255 | 256 | } else { |
| 256 | | return buf_print_u64(out_buf, u64(x)); |
| 257 | return buf_print_unsigned(uint)(out_buf, uint(x)); |
| 257 | 258 | } |
| 258 | 259 | } |
| 259 | 260 | |
| 260 | | pub fn buf_print_u64(out_buf: []u8, x: u64) -> isize { |
| 261 | pub const buf_print_i64 = buf_print_signed(i64); |
| 262 | |
| 263 | pub fn buf_print_unsigned(T: type)(out_buf: []u8, x: T) -> isize { |
| 261 | 264 | var buf: [max_u64_base10_digits]u8 = undefined; |
| 262 | 265 | var a = x; |
| 263 | 266 | var index: isize = buf.len; |
| ... | ... | @@ -278,6 +281,8 @@ pub fn buf_print_u64(out_buf: []u8, x: u64) -> isize { |
| 278 | 281 | return len; |
| 279 | 282 | } |
| 280 | 283 | |
| 284 | pub const buf_print_u64 = buf_print_unsigned(u64); |
| 285 | |
| 281 | 286 | pub fn buf_print_f64(out_buf: []u8, x: f64, decimals: isize) -> isize { |
| 282 | 287 | const numExpBits = 11; |
| 283 | 288 | const numRawSigBits = 52; // not including implicit 1 bit |