| 101 | } |
| 102 | |
| 103 | int itoa64(i64 value, char *sp, int radix) { |
| 104 | char tmp[32]; // Buffer for 64-bit integer (max 65 chars for base 2 + sign) |
| 105 | char *tp = tmp; |
| 106 | int i; |
| 107 | u64 v; |
| 108 | |
| 109 | int sign = (radix == 10 && value < 0); |
| 110 | if (sign) |
| 111 | v = -static_cast<u64>(value); |
| 112 | else |
| 113 | v = static_cast<u64>(value); |
| 114 | |
| 115 | while (v || tp == tmp) { |
| 116 | i = v % radix; |
| 117 | v = radix ? v / radix : 0; |
| 118 | if (i < 10) |
| 119 | *tp++ = i + '0'; |
| 120 | else |
| 121 | *tp++ = i + 'a' - 10; |
| 122 | } |
| 123 | |
| 124 | int len = tp - tmp; |
| 125 | |
| 126 | if (sign) { |
| 127 | *sp++ = '-'; |
| 128 | len++; |
| 129 | } |
| 130 | |
| 131 | while (tp > tmp) |
| 132 | *sp++ = *--tp; |
| 133 | |
| 134 | *sp = '\0'; // Null-terminate the string |
| 135 | return len; |
| 136 | } |
| 137 | |
| 138 | int utoa32(u32 value, char *sp, int radix) { |
| 139 | char tmp[16]; // be careful with the length of the buffer |
no outgoing calls
no test coverage detected