[swift-evolution] Arbitrary-sized integers

David Sweeris davesweeris at mac.com
Wed Jun 15 14:10:07 CDT 2016


> On Jun 15, 2016, at 10:58 AM, Félix Cloutier via swift-evolution <swift-evolution at swift.org> wrote:
> 
> I know that one, but I merely need fixed-size big integers. Backing all of my integers with an array seems overly expensive.
> 
> Félix
> 
>> Le 14 juin 2016 à 23:25:16, T.J. Usiyan <griotspeak at gmail.com <mailto:griotspeak at gmail.com>> a écrit :
>> 
>> There is also a fairly robust implementation of arbitrary size integers here https://github.com/lorentey/BigInt/tree/master/Sources <https://github.com/lorentey/BigInt/tree/master/Sources>
>> 
>> On Tue, Jun 14, 2016 at 10:02 PM, Charlie Monroe via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> 128-bit Ints have been discussed here a few weeks ago:
>> 
>> https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160523/018957.html <https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160523/018957.html>
>> 
>>> On Jun 15, 2016, at 5:50 AM, Félix Cloutier via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>> 
>>> I'm writing a program that would need Int128s. Since Swift uses LLVM and LLVM has good support for arbitrary-sized integers (well, up to 2^24 bits anyways), I was wondering if there was any interest in having arbitrary-sized integers in Swift.
>>> 
>>> Félix


When you say “LLVM has good support for arbitrary-sized integers”, what does that mean? Also, I wouldn’t say that "Swift uses LLVM"… The only (complete) Swift compiler that I’m aware of is built on the LLVM infrastructure, and Xcode does use many of LLVM’s (and LLDB's) features to do its IDE voodoo, but the language itself doesn’t require any particular compiler to be used. In light of that, I’m not sure it’s wise to be tying Swift’s standard library so closely to something that’s strictly part of LLVM. OTOH, I’m also not sure it’d be any harder to add a few bigint types to a compiler than to a library, so maybe that doesn’t really matter in this case.

What about creating UInt/Int128, UInt/Int256, etc up to the largest size which can fit in the target’s SIMD unit? That should allow for Int128 to be pseudo-natively handled on any CPU Swift is officially targeting, but wider than that and I’m not sure (also it obviously would use the SIMD unit, which may not be what you want)

How would this affect the `IntMax` typealias and its associated functions?

- Dave Sweeris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160615/7d620044/attachment.html>


More information about the swift-evolution mailing list