<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">For the record, I agree with Jeremy (and Dave, and Zhaoxin). I articulated most of the same thoughts on the bug Jason filed when he thought this would be uncontroversial. (This discussion is showing that it <i class="">is</i>&nbsp;controversial and I'm perfectly glad to be having it.)</div><div class=""><br class=""></div><div class="">Jordan</div><br class=""><div><blockquote type="cite" class=""><div class="">On Jan 18, 2016, at 4:51, Jeremy Pereira via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">I think I disagree with you.<br class=""><br class="">It is true that in mathematics people generally write (-x)^n to raise -x to the nth power but the notation of exponentiation (i.e. the n is a superscript to the x) makes it look like a postfix operator that binds more tightly than the negation. The general rule in Swift is that pre- and postfix have higher precedence and I don’t think this should be changed just because they do it slightly differently in maths. There’s no equivalent visual cue to superscripting that can make it look like ** binds more tightly than unary minus and I think people who are used to Swift conventions will find it confusing, especially considering that exponentiation is just one of an infinitude of possible binary operators. <br class=""><br class="">Furthermore, many people including myself like to put spaces around our binary operators. So you can argue that <br class=""><br class=""> &nbsp;&nbsp;&nbsp;-3**2 <br class=""><br class="">should be -9 (although according to Swift conventions, it obviously is not) but what about <br class=""><br class=""> &nbsp;&nbsp;&nbsp;-3 ** 2 <br class=""><br class="">To me, that reads as (-3)**2 pretty unambiguously.<br class=""><br class="">You could argue that I should change my formatting conventions in the case of higher-than-prefix-precedence binary operators but<br class=""><br class=""> &nbsp;&nbsp;&nbsp;-3**-2 <br class=""><br class="">and<br class=""><br class=""> &nbsp;&nbsp;&nbsp;someOptional!**2<br class=""><br class="">won’t even compile. You need to put the spaces in so that Swift can identify the operators. <br class=""><br class=""><blockquote type="cite" class="">On 17 Jan 2016, at 18:19, Jason Nielsen via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><br class="">I'm afraid that is not a correct statement. &nbsp;There is no arguing that -3^2 is -9 and that -3^2 and 0-3^2 are equivalent mathematically. &nbsp;Exponentiation has higher precedence than - and subtraction is definitely an operator so -3^2 != (-3)^2. &nbsp;&nbsp;That swift has decided that -3 is different than 0 -3 (which is an error) is a language design choice which I think is not a good one (just my opinion of course). &nbsp;I can't think of any other language that is used for numerics R, matlab, python etc. that makes spacing like this significant). &nbsp;I realize that you are saying that -3 is a negative number but what is a negative number by definition? &nbsp;This is all strange to me.. if you type -3 at the REPL you get -3 if you type +3 you get an error. &nbsp;So +3 isn't a positive number? <br class=""><br class="">Best regards,<br class="">Jason<br class=""><br class="">On Sun, Jan 17, 2016 at 11:48 AM, David Sweeris via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class="">In that context, I would say 9 is the correct answer. Mathematically speaking, the "-" is part of the number, not an operator.<br class=""><br class="">At least I think that's how it worked last time I was in math class.<br class=""><br class="">- Dave Sweeris<br class=""><br class="">On Jan 17, 2016, at 08:24, Maximilian Hünenberger via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><br class=""><blockquote type="cite" class="">It's true prefix operators have the highest precedence (like ∞) but it should be lower so `-3**2` gets mathematically correct evaluated to `-9` if such an expression appears.<br class=""><br class="">- Maximilian<br class=""><br class="">Am 17.01.2016 um 02:36 schrieb 肇鑫 &lt;<a href="mailto:owenzx@gmail.com" class="">owenzx@gmail.com</a>&gt;:<br class=""><br class=""><blockquote type="cite" class="">I think they are already the highest precedence. That why they need not to be set this property. <br class=""><br class="">Also, I think things like <br class=""><br class="">print(-3**2)<br class="">print(0-3**2)<br class=""><br class="">should never appear in Swift. As it is hard for human to read. <br class=""><br class="">zhaoxin<br class=""><br class=""><br class="">On Sun, Jan 17, 2016 at 5:21 AM, Maximilian Hünenberger &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class="">+1 for me and as far as values go:<br class=""><br class="">prefix -<br class="">precedence 150, same as infix * since it is essentially (-1)*<br class=""><br class="">prefix +<br class="">same as prefix -<br class=""><br class=""><br class="">To break the least amount of code:<br class=""><br class="">prefix !<br class="">precedence 140, which is higher than any other Bool operator (== is highest with 130)<br class=""><br class="">prefix ~<br class="">precedence 170, which is higher than any other binary operator (&lt;&lt; is highest with 160)<br class=""><br class=""><blockquote type="cite" class="">Am 16.01.2016 um 16:30 schrieb Jason Nielsen via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt;:<br class=""><br class="">Hi all,<br class=""><br class="">My proposal is to add a precedence option for prefix and postfix operators. &nbsp;It is great that swift allows for associativity and precedence for binary operators but it hasn't quite gone all the way to make operator overloading fully functional (just an opinion). &nbsp;To illustrate consider the following code:<br class=""><br class="">import CoreFoundation<br class=""><br class="">infix operator ** { associativity right precedence 200 }<br class=""><br class="">func ** (base: Double, power: Double) -&gt; Double {<br class=""> &nbsp;&nbsp;&nbsp;return pow(base, power)<br class="">}<br class=""><br class="">print(-3**2)<br class="">print(0-3**2)<br class=""><br class="">which prints 9 and -9. &nbsp;In the first case because unary minus has higher precedence as a prefix operator it evaluates to (-3)*(-3) and the second because - is viewed as a binary operator of lower precedence as (0-(3*3). &nbsp;Exponentiation has higher precedence than subtraction so -3**2 should be -9 and the two expressions above are mathematically equivalent. &nbsp;I originally reported this as a bug (SR-552) as to me the point of operator overloading is to allow you to write numerical expressions cleanly but should give you the correct mathematical result. &nbsp;The only really useful application I can think of for operator overloading is basically as a DSL for numerical expressions. &nbsp;If it doesn't allow you to get correct results without having to put brackets everywhere it sort of defeats the purpose (just my opinion of course).<br class=""><br class="">Best regards,<br class="">Jason<br class="">_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></blockquote>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""><br class=""></blockquote>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></blockquote><br class="">_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""><br class=""><br class="">_______________________________________________<br class="">swift-evolution mailing list<br class="">swift-evolution@swift.org<br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></blockquote><br class="">_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></div></blockquote></div><br class=""></body></html>