Yes, Go will evaluate as specified in the spec. So it can't do (a*3.0)/2.0 
as a*(3.0/2.0). At least, it always needs to produce results *as if* the 
former was used.
Normally for floats that means it does the ops exactly in the order 
specified. For integers there are often rewrites that will make it faster 
but still produce the results required by the spec. e.g. (2*x)+(2*y) == 
2*(x+y) works for ints (but not floats).

On Saturday, May 29, 2021 at 4:03:57 PM UTC-7 axel.wa...@googlemail.com 
wrote:

> I would read it that way, yes. Note that regardless of the spec you can 
> always indicate the intended precedence using parenthesis. If in doubt, I'd 
> recommend to do that - if you are in doubt, the reader of the code will be 
> as well.
>
> On Sun, May 30, 2021 at 12:54 AM Scott Pakin <scot...@pakin.org> wrote:
>
>> When the Operator precedence 
>> <https://golang.org/ref/spec#Operator_precedence> section of the 
>> language specification says that "Binary operators of the same precedence 
>> associate from left to right. For instance, x / y * z is the same as (x 
>> / y) * z", does this imply that the language guarantees that a*3.0/2.0 
>> will always be evaluated as (a*3.0)/2.0 and never as a*(3.0/2.0), even 
>> though the constant expression can be computed at compile time?  Does this 
>> hold for integer types, too (e.g., a*3/2)?
>>
>> Thanks,
>> — Scott
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to golang-nuts...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/golang-nuts/4f64105d-7ecb-4cf8-a18f-d045ace5e9ecn%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/golang-nuts/4f64105d-7ecb-4cf8-a18f-d045ace5e9ecn%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/13b59903-c2d6-4524-b77b-524b0e583f4cn%40googlegroups.com.

Reply via email to