Skip to content

Instantly share code, notes, and snippets.

@LeFreq
Last active December 22, 2015 18:59
Show Gist options
  • Save LeFreq/6517115 to your computer and use it in GitHub Desktop.
Save LeFreq/6517115 to your computer and use it in GitHub Desktop.
How to implement arbitrarily-sized integers.
Arbitrary-precision arithmetic (aka BigNums)
(R) Registered Mark Janssen under Creative Commons: BY; idea can be used commercially if attribution is given in the credits and the resulting software if available freely to author or website is available to public.
The right way to think about implementing arbitrarily-sized integers is to use base-256 encoding and using simple ASCII strings (i.e. Ascii-Coded Binary).
To make an arbitrary precision *real* number, use Bigint to make an "Rational" class that simply uses two BigInts as numerator and denominator.
Now you have an exact, lossless way to represent any (finite) "real" number.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment