Int256 in Swift

Viewed 1472

I've been looking around for implementations of Int256 and Int128 in Swift. They seem to be possible to construct now that Swift 4 is out but I haven't found any good implementations.

StackOverflow seems to be devoid of any solutions for now, hopefully this can be a starting place for people in the future looking for this now that Swift 4/Xcode 9.1 are in the wild.

2 Answers

In facing this problem myself, I have managed to find a couple implementations close but not exactly what you’re looking for. Where I get an implication that you’re looking for signed integers (by the use of Int instead of UInt), I have only been able to find implementations of UInt—unsigned integers—at these bit widths.

Here are the links to the repos on GitHub:

In any case, these projects are likely good starting points to use toward implementing signed integers at these bit widths. You might be able to check around GitHub to see how implementations of signed and unsigned integers differ at the same bit width, if you need to.

Apple has had an implementation for large integers (signed/unsigned 128, 256. 512 and 1024 bit) for a while as part of the Accelerate framework; you can find them in VecLib. For example:

struct vS128 A union containing one vSInt32 vector or four 32-bit integers, representing a 128-bit signed integer.

Related