[swift-evolution] Rename Number Type Bitwise Operators

davesweeris at mac.com davesweeris at mac.com
Thu Jan 7 22:42:11 CST 2016


While we’re (sorta) on the topic, is there any chance the bitwise operators (“&”, “|”, and "^") could be renamed to ".&”, ".|”, and ".^”? Or maybe only defined for some sort of Bitfield<T> wrapper type? “^” already has a numeric meaning (3^2 = 9), and “|” and “&” are a convenient custom operators (they’re easy to recognize and I think are the only two single-character vclid operators that doesn’t require obscure keystrokes to type and don’t already have a fairly obvious meaning).

(Mostly I’m interested in “|” and “^”, but it’d be weird and confusing to treat “&” specially.)



> On Jan 6, 2016, at 15:39, Dave Abrahams via swift-evolution <swift-evolution at swift.org> wrote:
> 
> 
>> On Jan 6, 2016, at 3:32 PM, James Campbell via swift-evolution <swift-evolution at swift.org> wrote:
>> 
>> There is a number of deficiencies with Swift and Numbers. Especially when trying to be clever with generics.
>> 
>> - The API exposes built in types like`BuiltIn.Word` as the return type of some APIs but there is no way to use said types.
>> - We have a Float and a Float80. Float and Doubles can't be initialised (via init) with anything but Integer values but Float80 can be initialized with both Floating Point and Integer
>> - We have a SignedNumberType but no UnsignedNumberType, All the floating points use this protocol, so shouldn't this be NumberType ?
>> - SignedIntegerType and UnsignedIntegerType have a way of generically constructing an Int as long as you cast it to the Maximum Int or UInt. But there is no such thing for Floating Point Numbers.
>> - We have Float80 and a typealised Float32 and Float64. Why couldn't  have triple as an extra type name, as having one true type with a number is confusing ? 
>> - If all number types could be initilized with all number types, then a lot of the constructors could be in the NumberType protocol.
> 
> We’re currently working on improving most of these things.  You can see some of our work in progress here:
> https://github.com/apple/swift/blob/master/test/Prototypes/Integers.swift.gyb
> https://github.com/apple/swift/blob/master/test/Prototypes/FloatingPoint.swift
> 
> 
> -Dave
> 
> 
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution



More information about the swift-evolution mailing list