-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
std.math.big.int: Support strings up to base 36 #22461
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM, Thanks! I'll rebase this branch for you and set it to auto merge when CI passes
4892401
to
1bd05a7
Compare
It looks like |
Ah indeed, I should have read the CI failures more carefully rather than assuming they were likely outdated transient failures that would be solved by a rebase. I don't see a trivial solution to that issue either, solving it properly seems like it would require some clear thinking about math that I don't want to get into right now. We could restrict the base to |
Just for triage purposes, what's the plan for this one? |
Not sure. Multiple options, in preferred order:
Something else that came up while investigating this: the current implementation of |
Another possible option would be to change |
The correct formula for However, only using integers (like in I think these functions should work: fn sizeInBaseUpperBound(self: Const, base: u8) usize {
const sign_byte = @as(u1, @intFromBool(!self.positive));
const bit_count_abs: f32 = @floatFromInt(self.bitCountAbs());
const base_f: f32 = @floatFromInt(base);
return @as(usize, @intFromFloat(bit_count_abs / std.math.log2(base_f))) + 1 + sign_byte;
}
// assumes `string_len` doesn't account for minus signs if the number is negative
fn calcSetStringLimbCount(string_len: usize, base: u8) usize {
const base_f: f32 = @intFromFloat(base);
const string_len_f: f32 = @intFromFloat(string_len);
return 1 + @as(usize, @intFromFloat(string_len_f * std.math.log2(base_f) / @bitSizeOf(Limb)));
} |
Thanks for the help! That seems to be off by one:
|
I have reproduced the issue, my function does not undershoot by one, but the multiply requires a temporary buffer which can be 1 larger than needed (to prevent overflows, but it doesn't happen in this case). |
Co-Authored-By: samy007 <[email protected]>
1bd05a7
to
301343b
Compare
A |
let's not miss the opportunity to add the additional error code to windows setEndPos implementation |
-> #22981 |
Merging this given @ifreund's earlier approval. |
Closes #22206.