FWIW the new integers proposal defines a quotientAndRemainder method for 
FixedWidthInteger protocol:
https://github.com/apple/swift-evolution/pull/598/files#diff-6ef84b28f2eaeb383265ccbb60650022R785
 
<https://github.com/apple/swift-evolution/pull/598/files#diff-6ef84b28f2eaeb383265ccbb60650022R785>

This is not the default you’re proposing, however...

Max

> On Feb 13, 2017, at 4:03 PM, Dan Stenmark via swift-evolution 
> <[email protected]> wrote:
> 
> (I get the feeling the response to this pitch will be overwhelming negative, 
> but *deep inhale* here I go!)
> 
> A common mistake I see programmers make is dividing two integers and 
> expecting a floating-point result.  This mostly affect new programmers who 
> haven't learned about ALUs yet, but I sometimes even see veterans make the 
> mistake when they don't realize that neither operand they're passing is 
> floating-point.
> 
> let foo = 17 / 5
> print( foo )    // Huh, why is this 3 and not 3.4?  Oh, wait, I'm an idiot.
> 
> I'd like to propose we make '/' operator on two Ints return a 
> quotient-remainder tuple by default.  This should help both new and veteran 
> programmers alike write less error-prone code.
> 
> let (quotient, remainder) = 17 / 5
> print( "Q:\(quotient) R:\(remainder)" )    // Idiot-proof!
> 
> Thoughts?
> 
> Dan
> _______________________________________________
> swift-evolution mailing list
> [email protected]
> https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to