hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

u64tos.ha (483B)


      1 // SPDX-License-Identifier: MPL-2.0
      2 // (c) Hare authors <https://harelang.org>
      3 
      4 fn u64tos(u: u64) (*[*]const u8, size) = {
      5 	static let buf: [20]u8 = [0...]; // len("18446744073709551615")
      6 	let sl = buf[..0];
      7 	if (u == 0) {
      8 		static append(sl, '0');
      9 	};
     10 	for (u > 0) {
     11 		static append(sl, (u % 10): u8 + '0');
     12 		u /= 10;
     13 	};
     14 	for (let s = 0z, e = len(sl) - 1; s < e) {
     15 		let tmp = sl[s];
     16 		sl[s] = sl[e];
     17 		sl[e] = tmp;
     18 		s += 1;
     19 		e -= 1;
     20 	};
     21 	return (sl: *[*]const u8, len(sl));
     22 };