I recently ran across the need for a large integer in Swift – something that needs more than the 64 bits provided by Int64. This is not the first time. I have played around with Swift Decimal in the past (NSDecimal, NSDecimalNumber) only to find they come up short in precisely representing a rational number. Python, for example, makes it trivial to find the Nth decimal place of any rational number by storing the repeating decimal pattern under the hood and making that info available to you.

This poor substitute of mine only supports the binary OR and POPULATION operations and has no string representation. But it worked for what I needed.


Leave a Reply