<div dir="ltr">I'm afraid that is not a correct statement. There is no arguing that -3^2 is -9 and that -3^2 and 0-3^2 are equivalent mathematically. Exponentiation has higher precedence than - and subtraction is definitely an operator so -3^2 != (-3)^2. 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). I can't think of any other language that is used for numerics R, matlab, python etc. that makes spacing like this significant). I realize that you are saying that -3 is a negative number but what is a negative number by definition? This is all strange to me.. if you type -3 at the REPL you get -3 if you type +3 you get an error. So +3 isn't a positive number? <div><br></div><div>Best regards,</div><div>Jason</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Jan 17, 2016 at 11:48 AM, David Sweeris via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div></div><div>In that context, I would say 9 is the correct answer. Mathematically speaking, the "-" is part of the number, not an operator.</div><div><br></div><div>At least I think that's how it worked last time I was in math class.</div><div><br></div><div>- Dave Sweeris</div><div><br>On Jan 17, 2016, at 08:24, Maximilian Hünenberger via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:<br><br></div><blockquote type="cite"><div><div></div><div>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.</div><div><br></div><div>- Maximilian</div><div><br>Am 17.01.2016 um 02:36 schrieb 肇鑫 <<a href="mailto:owenzx@gmail.com" target="_blank">owenzx@gmail.com</a>>:<br><br></div><blockquote type="cite"><div><div dir="ltr"><div class="gmail_default" style="font-family:georgia,serif">I think they are already the highest <span style="font-family:arial,sans-serif;font-size:13px">precedence</span>. That why they need not to be set this property. </div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default" style="font-family:georgia,serif">Also, I think things like </div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><font face="georgia, serif">print(-3**2)<br></font><font face="georgia, serif">print(0-3**2)</font></blockquote><div class="gmail_default"><font face="georgia, serif"><br></font></div><div class="gmail_default"><font face="georgia, serif">should never appear in Swift. As it is hard for human to read. </font></div><div class="gmail_default"><font face="georgia, serif"><br></font></div><div class="gmail_default"><font face="georgia, serif">zhaoxin</font></div><div class="gmail_default"><font face="georgia, serif"><br></font></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Jan 17, 2016 at 5:21 AM, Maximilian Hünenberger <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">+1 for me and as far as values go:<br>
<br>
prefix -<br>
precedence 150, same as infix * since it is essentially (-1)*<br>
<br>
prefix +<br>
same as prefix -<br>
<br>
<br>
To break the least amount of code:<br>
<br>
prefix !<br>
precedence 140, which is higher than any other Bool operator (== is highest with 130)<br>
<br>
prefix ~<br>
precedence 170, which is higher than any other binary operator (<< is highest with 160)<br>
<div><div><br>
> Am <a href="tel:16.01.2016" value="+8616012016" target="_blank">16.01.2016</a> um 16:30 schrieb Jason Nielsen via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>>:<br>
><br>
> Hi all,<br>
><br>
> My proposal is to add a precedence option for prefix and postfix operators. 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). To illustrate consider the following code:<br>
><br>
> import CoreFoundation<br>
><br>
> infix operator ** { associativity right precedence 200 }<br>
><br>
> func ** (base: Double, power: Double) -> Double {<br>
> return pow(base, power)<br>
> }<br>
><br>
> print(-3**2)<br>
> print(0-3**2)<br>
><br>
> which prints 9 and -9. 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). Exponentiation has higher precedence than subtraction so -3**2 should be -9 and the two expressions above are mathematically equivalent. 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. The only really useful application I can think of for operator overloading is basically as a DSL for numerical expressions. 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>
><br>
> Best regards,<br>
> Jason<br>
</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>
_______________________________________________<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><br></div>
</div></blockquote></div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></div><br>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">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>
<br></blockquote></div><br></div>