The bignum bug(s) #9
Labels
No labels
bug
duplicate
enhancement
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: simon/post-scarcity#9
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
At some point in development I had bignums of two cells more or less working, but I've never had bignums of three cells working. Part of the problem here is I don't really understand C well enough to know exactly what's going on, and I don't have good enough debugging tools (or am not using them well enough) to see what's going on.
The following scratchpad shows that at one point we were getting past the first bignum barrier, but even this no longer works.
The system can manage integers up to beyond +- 1,000,000,000,000,000,000 (1018), and although I really want bignums to work, that's probably good enough for now.
In the 0.0.5 build, we are managing numbers just across the bignum boundary:
We can even add numbers to them, for small values of numbers.
if we consider that 260 (1,152,921,504,606,846,976) is, to our bignum system, the equivalent of 10 to the decimal system, then 1,152,921,504,606,846,977 is the equivalent of 11, and, as we see from the inspector above, 1,152,921,504,606,846,978 is the equivalent of 12. I can add 1,152,921,504,606,846,975 — the equivalent of 9 — to itself and get a valid number:
That's the equivalent of 18 on this analogy, and you can see that the first digit is 1, and the second 'digit' is two less than the equivalent of 10, so that this is correct. But when I try to multiply 1152921504606846975 by 1152921504606846975, the equivalent of 81 to pursue the analogy,
Further exploration is needed to find exactly where it does break down. But we have got a regression, because the pre-release build for 0.0.6 can't even do this.
Last night's (or rather, very early this morning's) investigations showed that
version 0.0.5's bignum arithmettic is less buggy (still buggy but less buggy)
than 0.0.6-SNAPSHOT's. This morning (proper) I experimentally tried integrating
0.0.5's version of
integer.cinto thedevelopbranch. Many bignum teststhen passed, but others went into non-terminating states. I've reset those
changes.
I've tagged 0.0.5 in the tree so that I can go back to it.
I decided that the responsible thing to do was get the 0.0.6 release out
without these changes, and then have another crack at the bignum problem.
OK, I'm now working in the 0.0.6 branch. There are certainly regressions, but I think the problems are more in
printthan inadd.Here, what's printed by
inspectlooks right, but what's printed by the REPL (and thus byprint) is wrong.Again, what's printed by
inspectlooks right, but what's printed by the REPL (and thus byprint) is wrong.However, in 0.0.6, multiply is definitely wrong:
I don't know whether that's a regression or not.
There is also a bug in
addthat's definitely a regression:I'm confident that that did work at one time.
H'mmm... 0.0.5 also gets that wrong, but differently.
So not a regression, exactly, but a change.
If, as proposed, in 0.1.0 I implement bignums in Lisp, there's a beautiful and easy-to-understand explanation of how they're implemented in ulisp here, which will make life simpler!