pif_LongInt

by Popisfizzy
Double, triple, and quadruple-precision integers, both signed and unsigned.
ID:2275001
 
Overall, this is a fairly minor set of changes. They've been sitting on my PC for more than a year, so a few days ago I decided to actually push the changes to Github and upload them to the hub. The good news is that now my code is actually available for download directly from the hub, instead of the using the zip link. Thanks goes to Super Saiyan X for the membership letting me do that!

The actually changes to the code are relatively insignificant. The biggest changes are that I've changed the name of the UnsignedDouble class to Unsigned32, and likewise changed SignedDouble to Signed32. I decided to do this for a few years: it's clearer the size available, it's more concise, and it extends more nicely to larger integer sizes. I'm going to follow this convention as I continue to add to the library and try to move it out of beta (whenever that may be).

Another miscellaneous change to the hub is that I noticed the demo code that is on the hub was wrong, and had been for a year, due to an error in one of the loops. I had
proc/Choose(n, k, type = /pif_LongInt/Unsigned32)
/*
* This method was found at:
* http://www.geeksforgeeks.org/space-and-time-efficient-binomial-coefficient/
*/


var/pif_LongInt/Int = new type(1)

// This forces the Int object to alter itself rather than produce a
// new object for each operation.
Int.SetModeFlag(Int.NEW_OBJECT, 0)

if(k > (n-k))
// Choose(n, k) = Choose(n, n-k) so by doing this we reduce the
// number of steps needed.
k = n-k

for(var/i = 0, i <= n, i ++)
Int.Multiply(n-i)
Int.Quotient(i+1)

return Int

while the for loop line should actually have been
  for(var/i = 0, i <= n, i ++)

I'm curious whether no one ever noticed, or no one ever cared to let me know.

If you use the library, let me know! It's always nice to know when something you make has fans. Likewise, if you encounter a bug, please post a report so I can get it taken care of.

Thanks for your support! :)

Changelog:
pif_LongInt Changelog
  • Renamed UnsignedDouble and SignedDouble to Unsigned32 and Signed32. This makes it clearer, in my opinion, what their precision is and this convention will be followed for all future classes.
  • "Emancipated" the Signed32 class from Unsigned32. That is, Signed32 was rewritten so that it is not a child of Unsigned32, and instead inherits directly from the pif_LongInt class. The approach of making Signed32 a child of Unsigned32 seemed a good idea originally, but in retrospect it is not as useful as it once seemed due to a realization I had regarding handling overflow exceptions. Furthermore, a Signed32 can not replace an Unsigned32 in a method and keep the same functionality, due to their significantly-different range and so it is also poor design. Doing it as a sister class of Unsigned32 involves copying more code, but it's a better way of doing it in the long run.
  • Fixed the joke /Signed32.PrintUnary() method so that it works correctly for negative numbers.
  • Fixed an bug with the Signed32 class that would result in it throwing an overflow exception in the cases when UnsignedDouble would have an overflow, even though the situations where signed and unsigned doubles overflow are very different.

Other Changes
  • You can now download the library directly from the hub, instead of having to download the zip. Thanks goes to Super Saiyan X for the membership, and so access again to my filespace.
  • The example code on my hub has been wrong for at least a year, due to a minor mistake in loop boundaries. Fixed now.

The MIT License
Copyright (c) 2016-2017 Timothy "popisfizzy" Reilly

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.