[swift-evolution] Shift operator: the type of the second operand
scanon at apple.com
Mon Dec 21 09:28:50 CST 2015
> On Dec 19, 2015, at 11:04 PM, Dave Abrahams via swift-evolution <swift-evolution at swift.org> wrote:
>> On Dec 19, 2015, at 8:02 PM, Chris Lattner via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>> On Dec 19, 2015, at 7:43 PM, Jordan Rose via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>> +1 to dropping the existing signatures and providing a consistent right-hand side.
>>> I'm a little concerned about not allowing Int as the shift type. Even though we disallow negative shifts, we generally encourage using 'Int' as the "vocabulary" type for integers, which means any shift by a non-constant amount might require a conversion. I do see that BigInts may be shifted by more than 2^64, however, so hardcoding Int wouldn't be right either.
>> Unless it is somehow sparsely encoded, a bigint with more than 2^64 bits couldn’t be held in memory.
> I don't believe bit shifting should be supported for BigInt anyway. The lossy semantics of bit shifting is pretty closely tied to fixed-width integers.
Yes, A BigInt type should probably eschew shift operators for this reason. Instead, I would rather have either a sparse representation for powers of two that can be used with the usual multiply / divide, or explicit multiplyByTwoToThe( ) and divideByTwoToThe( ) functions (names to be bikeshedded, obviously).
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution