-
-
Notifications
You must be signed in to change notification settings - Fork 741
Issue 14503: Implement formatting BigInt in octal #3992
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
Conversation
*/ | ||
char[] toOctalString() const | ||
{ | ||
auto predictLength = 8*BigDigitBits / 3; |
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.
Perhaps you meant to use the actual length here.
Otherwise, the following code gives a range check error in biguintcore.d on line 1588:
import std.array, std.bigint, std.range, std.stdio;
void main () {
auto a = BigInt ("1" ~ ("0".repeat (10000).join ("")));
writefln ("%o", a);
}
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.
An assertion may be added to check that exactly 0, 1, or 2 characters of the predicted length are wasted.
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.
Good catch, I wasn't paying attention and failed to actually multiply by data.length
. Fixed.
Hmph, actually, |
No worries, I fixed the problem. Hopefully it will pass now. Thanks for finding all the problems! |
Actually, even that assumption is not necessarily true, if the upper words of the |
dffcc50
to
77d0697
Compare
With the current assertion, the following passes now (32-bit):
So perhaps the statement is right. |
Maybe try |
Yeah, if "no leading zero words" is not explicitly guaranteed somewhere, the assertion is still wrong and should be taken out. |
A descending loop also works fine:
But who knows what else won't work :) . If leading zero words ever appear, or will appear, this particular assertion would be a wrong place to signal that anyway. |
I glanced through the various operations, and it seems that a lot (all?) of them allocate new arrays for storing the result of operations. I'm not sure how accurate the array size estimates are, whether there might be leading zero words or not. So better leave the assert out. |
Hmm, autotester is failing... I wonder if there's some problems with the length prediction code?? |
Found while trying to test this PR: https://issues.dlang.org/show_bug.cgi?id=15678 |
Fixed: #3995 |
Carried bits in last word must be output at the end. Add unittest for 3rd/4th word no-carry boundary. Implement 'o' format specifier in BigInt.toString().
77d0697
to
6282dda
Compare
Rebased. #3995 has been merged; any other issues? |
LGTM |
ping random reviewers @andralex @JakobOvrum @schveiguy @klickverbot @DmitryOlshansky |
size_t penPos = buff.length - 1; | ||
size_t lastNonZero = buff.length - 1; | ||
|
||
pragma(inline) void output(int digit) @nogc nothrow |
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.
Why is this accepting int
? Every call to this is with an unsigned type, and most of them are size_t
.
May be a good reason, but I feel like this should be size_t
or ptrdiff_t
-- i.e. whatever is natural for the architecture.
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.
You're right, this should not accept a signed integer type. I refrained from using size_t
because the range of parameters should always be < 8 (otherwise there is a bug). No need to use 64 bits when 32 bits already suffices (in fact, just 4 bits already suffice, but requiring anything smaller than 32 bits requires ugly casts and doesn't necessarily make the generated asm any better).
Implementation looks sound. Is there a reason you didn't implement |
I'm leaving |
Auto-merge toggled on |
Second part of fix to: https://issues.dlang.org/show_bug.cgi?id=14503