From: "alexeymuranov (Alexey Muranov)" <redmine@...>
Date: 2012-11-12T03:33:50+09:00
Subject: [ruby-core:49232] [ruby-trunk - Feature #7328] Move ** operator precedence under unary + and -


Issue #7328 has been updated by alexeymuranov (Alexey Muranov).


In mathematical notation, when possible, the "minus operation" is usually introduced as the unary negation, and "a - b" is usually defined as a shorthand notation for "a + (-b)".  To avoid any ambiguity, as far as i know (but i do not have a reference), the minus and the plus, both binary and unary, have all the same precedence.  To the best of my knowledge, the expression "a * - b" is not a valid syntax in mathematics, at least in languages i am familiar with.

trans (Thomas Sawyer) wrote:
> @alexeymuranov Okay, I see what you are saying. But I think the problem really is that mathematical notation tends to be a little too conventional and variant for a programming language, which needs to be more precise. In equations, the negative sign tends to either negate the whole, or is used to mean subtraction. It rarely occurs in the middle somewhere as a negation because it gets factored out to the whole. So it is rarely an issue.
> 
> For programming however, it would kind of suck if `* -2` was an error b/c `*` is applied before `-`. And it could get rather complicated if Ruby tried to apply one order in one case and another order in another.


----------------------------------------
Feature #7328: Move ** operator precedence under unary + and -
https://bugs.ruby-lang.org/issues/7328#change-32789

Author: boris_stitnicky (Boris Stitnicky)
Status: Rejected
Priority: Normal
Assignee: 
Category: 
Target version: 


I would like to ask to consider decreasing ** operator precedence just below that of -/+ unary operators. I know that other languages (eg. Python) have ** operator bind tighter than negation, but seeing -1 ** 0.5 give the result -1 and having to type parenthesis (-1) ** 0.5... Even if it's not worth changing, I'd like to hear this rationalized. I've asked about rationalization of this on SO, and nobody seems to know why this precedence is the way it is.


-- 
http://bugs.ruby-lang.org/