<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body><div>On Fri, Dec 18, 2015, at 03:40 PM, August Joki wrote:<br></div>
<blockquote type="cite"><div> </div>
<div><blockquote type="cite"><div>On 18 Dec, 2015, at 15:31, Kevin Ballard via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br></div>
<div> </div>
<div><div><div>On Fri, Dec 18, 2015, at 03:04 PM, Chris Lattner via swift-evolution wrote:<br></div>
<blockquote type="cite"><div> </div>
<div><blockquote type="cite"><div>On Dec 18, 2015, at 3:03 PM, Stephen Canon <<a href="mailto:scanon@apple.com">scanon@apple.com</a>> wrote:<br></div>
<div> </div>
<div><div style="word-wrap:break-word;-webkit-line-break:after-white-space;"><div> </div>
<div><blockquote type="cite"><div>On Dec 18, 2015, at 5:57 PM, Chris Lattner <<a href="mailto:clattner@apple.com">clattner@apple.com</a>> wrote:<br></div>
<div> </div>
<div><div style="word-wrap:break-word;-webkit-line-break:after-white-space;"><div>On Dec 18, 2015, at 1:12 PM, Stephen Canon via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br></div>
<div><blockquote type="cite"><div><div style="word-wrap:break-word;-webkit-line-break:after-white-space;"><div>Hi everybody —<br></div>
<div> </div>
<div>I’d like to propose removing the “%” operator for floating-point types.<br></div>
</div>
</div>
</blockquote><div> </div>
<div>I support removing this - it is actively harmful for a surprising operation like this to have such short and inviting syntax. As asked downthread, have you given any thought into whether a Decimal type would support this operation?<br></div>
</div>
</div>
</div>
</blockquote><div> </div>
</div>
<div>The same concerns apply to decimal. It makes sense to have the operation (for both binary and decimal floating-point) as “Type.remainder(a,b)” or a free function like "remainder(a, b)”, but I would prefer not to use the operator “%” for it because it behaves very differently from integer %, and in ways that are not at all obvious to most users.<br></div>
</div>
</div>
</blockquote><div> </div>
</div>
<div>Great, I’d prefer decimal and the float types to have a consistent interface where possible. +1 from me on the proposal.<br></div>
</blockquote><div> </div>
<div>Agreed. +1 from me too. The `10.0 % 0.1` behavior is sufficiently surprising that I think that justifies removal by itself.<br></div>
<div> </div>
<div>I'm also in favor of adding mod and remainder as instance methods of the floating point types, e.g. `10.0.mod(0.1)` (as opposed to static methods or free functions).<br></div>
</div>
</div>
</blockquote><div>Shouldn’t that be added to any Arithmetic type?<br></div>
</div>
</blockquote><div> </div>
<div>IntegerArithmeticType already defines the % operator, adding a mod() method would just be duplication. If we have Float.remainder() then arguably we might want an integral remainder too, although remainder turns out to be rarely what people want (at least, for integral calculations), which is why the % operator is mod.<br></div>
<div> </div>
<div>-Kevin Ballard</div>
</body>
</html>