[swift-evolution] [Pitch] Int / Int returns Quotient-Remainder Tuple

Timothy Wood tjw at me.com
Mon Feb 13 18:12:47 CST 2017

> On Feb 13, 2017, at 4:03 PM, Dan Stenmark via swift-evolution <swift-evolution at swift.org> wrote:
> let (quotient, remainder) = 17 / 5
> print( "Q:\(quotient) R:\(remainder)" )    // Idiot-proof!

This would seem pretty reasonable to me if instead of a tuple, it returned a Rational struct where Int(_ rational: Rational) would do what “17 / 5” does right now. In this case you could have the hint provided by the extra “Int(…)” and an error if you missed it, but with less verbiage. The compiler could (in theory) skip the remainder calculation if you never accessed the remainder.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170213/3fe119d1/attachment.html>

More information about the swift-evolution mailing list