Arbitrary-sized integers

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

128-bit Ints have been discussed here a few weeks ago:

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@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

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

There's an implementation of DoubleWidth integers in
https://github.com/apple/swift/blob/master/test/Prototypes/Integers.swift.gyb#L926\.
We are planning to bring forward a proposal for integer protocols RSN™
that would allow you to write Int128 as

    typealias Int128 = DoubleWidth<Int64>

HTH,

···

on Tue Jun 14 2016, Félix Cloutier <swift-evolution@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.

--
-Dave

There is also a fairly robust implementation of arbitrary size integers
here https://github.com/lorentey/BigInt/tree/master/Sources

···

On Tue, Jun 14, 2016 at 10:02 PM, Charlie Monroe via swift-evolution < swift-evolution@swift.org> wrote:

128-bit Ints have been discussed here a few weeks ago:

[swift-evolution] [Idea] A 128-bit unsigned integer value type

On Jun 15, 2016, at 5:50 AM, Félix Cloutier via swift-evolution < > swift-evolution@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

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

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@gmail.com> a écrit :

There is also a fairly robust implementation of arbitrary size integers here https://github.com/lorentey/BigInt/tree/master/Sources

On Tue, Jun 14, 2016 at 10:02 PM, Charlie Monroe via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:
128-bit Ints have been discussed here a few weeks ago:

[swift-evolution] [Idea] A 128-bit unsigned integer value type

On Jun 15, 2016, at 5:50 AM, Félix Cloutier via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@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

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution

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

···

On Jun 15, 2016, at 10:58 AM, Félix Cloutier via swift-evolution <swift-evolution@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@gmail.com <mailto:griotspeak@gmail.com>> a écrit :

There is also a fairly robust implementation of arbitrary size integers here https://github.com/lorentey/BigInt/tree/master/Sources

On Tue, Jun 14, 2016 at 10:02 PM, Charlie Monroe via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:
128-bit Ints have been discussed here a few weeks ago:

[swift-evolution] [Idea] A 128-bit unsigned integer value type

On Jun 15, 2016, at 5:50 AM, Félix Cloutier via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@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