> On Apr 14, 2016, at 11:48 PM, Nicola Salmoria <[email protected]>
> wrote:
>
>> /// The quotient of `self` dividing by `rhs`.
>> // Arithmetic provides a default implementation of this method in terms
>> // of the mutating `divide` operation.
>> @warn_unused_result
>> func divided(by rhs: Self) -> Self
>>
>> /// Divides `self` by `rhs`.
>> mutating func divide(by rhs: Self)
>
> When dealing with integer arithmetic, I often find useful a `divmod` function
> which produces a (quotient, remainder) pair.
> It could be argued that such a pair is the primary result of division on
> integers. It would be great to have such a function included in the design.
I believe that it’s present in the latest draft of the Integer protocols.
>> /// SignedArithmetic protocol will only be conformed to by signed numbers,
>> /// otherwise it would be possible to negate an unsigned value.
>> ///
>> /// The only method of this protocol has the default implementation in an
>> /// extension, that uses a parameterless initializer and subtraction.
>> public protocol SignedArithmetic : Arithmetic {
>> func negate() -> Self
>> }
>
> It might make sense to also have a
>
> public protocol InvertibleArithmetic : Arithmetic {
> func inverted() -> Self
> }
>
> FloatingPoint would conform to this protocol, returning 1/x, while integer
> types would not.
That’s a very reasonable suggestion (and one that can easily be added
separately if it doesn’t make it into this batch of changes).
– Steve_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution