Right. I asked about this issue some months ago on this list, and Chris was very patient to confirm that what you described was indeed the thinking behind the rationalized precedence of bitwise operators in Swift.<br><br><br><div class="gmail_quote"><div dir="ltr">On Mon, Aug 1, 2016 at 23:18 Félix Cloutier &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">I disagree. The binary operators have properties that are comparable to arithmetic operators, and their precedence is easy to define as such. &amp; has multiplication-like properties (0*0=0, 0*1=0, 1*0=0, 1*1=1); | has addition-like properties (0+0=0, 0+1=1, 1+0=1, 1+1=2); ^ has subtraction-like properties (0-0=0, 0-1=-1, 1-0=1, 1-1=0), and their precedences are set accordingly (&amp; is multiplicative, | and ^ are additive).<div><div><div><br></div><div>The same applies to &amp;&amp; and ||. Bit shifts are exponentiative.</div><div><br></div><div>Binary operators get especially confusing in some languages because their precedence is lower than comparison operators. For instance, in C, `a &amp; b == c` gets parsed as `a &amp; (b == c)`. In Swift, the precedence of binary operators is above that of comparison operators, so we don&#39;t have that problem.</div><div><div></div></div></div></div></div><div style="word-wrap:break-word"><div><div><div><div><div>
<br><span style="color:rgb(0,0,0);font-family:&#39;Lucida Grande&#39;;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;display:inline!important;float:none">Félix</span>
</div></div></div></div></div></div><div style="word-wrap:break-word"><div><div><div><div>
<br><div><blockquote type="cite"><div>Le 1 août 2016 à 20:48:21, Rob Mayoff via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; a écrit :</div><br><div><div><blockquote type="cite"><blockquote type="cite">1 | 2 ^ 3   // or this?<br></blockquote><br><br>No. Both of those are bitwise operations. They are often used together. They<br>have a refined relative precedence in Swift that makes sense.<br></blockquote><br>I have no idea what the relative precedence of those operators is in<br>Swift, C, or any other language, and thinking about it now, no<br>relative precedence seems sensible or obvious to me. Those operators<br>(and bitwise-&amp;) are excellent examples of operators that should<br>require parentheses.<br>_______________________________________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div></div></blockquote></div><br></div></div></div></div></div>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div>