Dotty: how to set operator precedence

Can anyone point me to information on how to set operator precedence in Dotty?
I was assuming that the expression r5 and r6 below would have the same result,
but they do not. It looks like r6 and r7 are equivalent.

    val r5 = (5*x2) / (3*x2)
    val r6 = 5*x2 / 3*x2
    val r7 = (5*x2 / 3)*x2

TIA

Multiplication and division have the same precedence. For r6, the division by 3 occurs, then the whole thing is multiplied by x2. For readability, I usually try to put the division last, as in

val r6 = 5 * x2 * x2 / 3

I don’t think operator precedence handling changed in dotty (at least I can’t find anything in the docs), which would mean it can not be customized. All operators use the fixed operator precedence defined by the language (which can be found here for Scala 2)

1 Like

Yup. I came to the same conclusion. Question is how to change it.

Thanks for the information. I was under the impression this had changed.

Operator precedence is not configurable. It follows a fixed set of rules defined in the language spec. And the precedence of * and / follows the regular mathematical precedence rules so not really surprising I’m afraid.

1 Like

8-( Thank you.

If you’re defining your own operators you can take a look at the rules and try to use them to your advantage.

I am defining my operators but its for numerical computation. Thanks for the link though.

As far as I know, the only way to change operator precedence is to use parentheses.

thanks