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.
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:
UInt256
: https://github.com/hyugit/UInt256 UInt128
: https://github.com/Jitsusama/UInt128 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.
However, this only applies if you want for macOS 10.0+
, since it is not available for iOS currently. (As you can see here )
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.