-
Notifications
You must be signed in to change notification settings - Fork 3
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
NBKFlexibleWidthKit #33
Comments
I've pondered normalization behaviors for a bit, and I wonder if there's merit in a dynamically-fixed-width type. This hypothetical integer type would be given a size at initialization, then behave much like a fixed-width type unless specifically told to resize or whatnot. I also imagine that you could build a canonical big integer type on top of it. Something like NBKDynamicWidthKit and NBKAutomaticWidthKit, where NBKAutomaticWidthKit provides automatic normalization. Hm. |
2's complement or sign(um)-magnitude, that is the question 💭 |
I'm inclined to go with sign-magnitude because then I can leverage the magnitude. I wonder whether I should go sign or signum, however. Integer solutions become infinitely less elegant once you step out of the fixed-width real. A sign is either asymmetrically normalized or produces two zero representations. A signum, on the other hand, duplicates information that is trivially derived by checking whether the magnitude is zero or not. Hm. |
One nice thing about allowing both positive and negative zero, however, is that you can manipulate the sign and magnitude independently; there's one less invariant to maintain. |
On a side note: I believe a two's complement in-memory solution is easier to implement because the as-if-two's-complement behavior is the biggest headache by far. I'm just not convinced I could make it as performant, because negating arbitrary two's complement is quite expensive compared to toggling a sign bit. Thought: I wonder if you can mitigate the cost with a lazy magnitude view 💭 |
I decided to go with sign-magnitude and embrace negative zero 🤗 |
Untangling NBKResizableWidthKit (#46) might take a while. Instead of a fixed-width-but-resizable storage model, I might opt for freestanding generic functions. That way the logic can be reused on buffer pointers, etc. I will see what works out. |
|
I have put a lot of effort into separating my models and algorithms. So NBKFlexibleWidthKit mostly handles branching, resizing and normalization logic, while NBKCoreKit takes care of the calculations. I find this approach easy to maintain and reason about. (#85) helps a lot. |
Given that auto-normalization is the main feature of these integers, |
Hm. I wonder if I should make it |
I'm working on a Big[U]Int™ module. That's it. That's the
tweetGitHub post.The text was updated successfully, but these errors were encountered: