| ... | @@ -2201,8 +2201,8 @@ pub const Const = struct { | ... | @@ -2201,8 +2201,8 @@ pub const Const = struct { |
| 2201 | } | 2201 | } |
| 2202 | | 2202 | |
| 2203 | /// To allow `std.fmt.format` to work with this type. | 2203 | /// To allow `std.fmt.format` to work with this type. |
| 2204 | /// If the integer is larger than `pow(2, 64 * @sizeOf(usize) * 8), this function will fail | 2204 | /// If the absolute value of integer is greater than or equal to `pow(2, 64 * @sizeOf(usize) * 8)`, |
| 2205 | /// to print the string, printing "(BigInt)" instead of a number. | 2205 | /// this function will fail to print the string, printing "(BigInt)" instead of a number. |
| 2206 | /// This is because the rendering algorithm requires reversing a string, which requires O(N) memory. | 2206 | /// This is because the rendering algorithm requires reversing a string, which requires O(N) memory. |
| 2207 | /// See `toString` and `toStringAlloc` for a way to print big integers without failure. | 2207 | /// See `toString` and `toStringAlloc` for a way to print big integers without failure. |
| 2208 | pub fn format( | 2208 | pub fn format( |
| ... | @@ -2231,13 +2231,11 @@ pub const Const = struct { | ... | @@ -2231,13 +2231,11 @@ pub const Const = struct { |
| 2231 | std.fmt.invalidFmtError(fmt, self); | 2231 | std.fmt.invalidFmtError(fmt, self); |
| 2232 | } | 2232 | } |
| 2233 | | 2233 | |
| 2234 | var limbs: [128]Limb = undefined; | 2234 | const available_len = 64; |
| 2235 | const needed_limbs = calcDivLimbsBufferLen(self.limbs.len, 1); | 2235 | if (self.limbs.len > available_len) |
| 2236 | if (needed_limbs > limbs.len) | | |
| 2237 | return out_stream.writeAll("(BigInt)"); | 2236 | return out_stream.writeAll("(BigInt)"); |
| 2238 | | 2237 | |
| 2239 | // This is the inverse of calcDivLimbsBufferLen | 2238 | var limbs: [calcToStringLimbsBufferLen(available_len, base)]Limb = undefined; |
| 2240 | const available_len = (limbs.len / 3) - 2; | | |
| 2241 | | 2239 | |
| 2242 | const biggest: Const = .{ | 2240 | const biggest: Const = .{ |
| 2243 | .limbs = &([1]Limb{comptime math.maxInt(Limb)} ** available_len), | 2241 | .limbs = &([1]Limb{comptime math.maxInt(Limb)} ** available_len), |
| ... | @@ -2804,8 +2802,8 @@ pub const Managed = struct { | ... | @@ -2804,8 +2802,8 @@ pub const Managed = struct { |
| 2804 | } | 2802 | } |
| 2805 | | 2803 | |
| 2806 | /// To allow `std.fmt.format` to work with `Managed`. | 2804 | /// To allow `std.fmt.format` to work with `Managed`. |
| 2807 | /// If the integer is larger than `pow(2, 64 * @sizeOf(usize) * 8), this function will fail | 2805 | /// If the absolute value of integer is greater than or equal to `pow(2, 64 * @sizeOf(usize) * 8)`, |
| 2808 | /// to print the string, printing "(BigInt)" instead of a number. | 2806 | /// this function will fail to print the string, printing "(BigInt)" instead of a number. |
| 2809 | /// This is because the rendering algorithm requires reversing a string, which requires O(N) memory. | 2807 | /// This is because the rendering algorithm requires reversing a string, which requires O(N) memory. |
| 2810 | /// See `toString` and `toStringAlloc` for a way to print big integers without failure. | 2808 | /// See `toString` and `toStringAlloc` for a way to print big integers without failure. |
| 2811 | pub fn format( | 2809 | pub fn format( |