{"action":"created","issue":{"url":"https://api.github.com/repos/golang/go/issues/11161","labels_url":"https://api.github.com/repos/golang/go/issues/11161/labels{/name}","comments_url":"https://api.github.com/repos/golang/go/issues/11161/comments","events_url":"https://api.github.com/repos/golang/go/issues/11161/events","html_url":"https://github.com/golang/go/issues/11161","id":87257955,"number":11161,"title":"cmd/gc: x op= y is not always equivalent to x = x op y.","user":{"login":"cznic","id":729580,"avatar_url":"https://avatars.githubusercontent.com/u/729580?v=3","gravatar_id":"","url":"https://api.github.com/users/cznic","html_url":"https://github.com/cznic","followers_url":"https://api.github.com/users/cznic/followers","following_url":"https://api.github.com/users/cznic/following{/other_user}","gists_url":"https://api.github.com/users/cznic/gists{/gist_id}","starred_url":"https://api.github.com/users/cznic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cznic/subscriptions","organizations_url":"https://api.github.com/users/cznic/orgs","repos_url":"https://api.github.com/users/cznic/repos","events_url":"https://api.github.com/users/cznic/events{/privacy}","received_events_url":"https://api.github.com/users/cznic/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-06-11T08:23:32Z","updated_at":"2015-06-12T08:41:11Z","closed_at":"2015-06-11T10:22:31Z","body":"From the [specs](http://golang.org/ref/spec#Assignments)\r\n\r\n> An *assignment operation x op= y* where *op* is a binary arithmetic operation is equivalent to *x = x op y* but evaluates `x` only once.\r\n\r\nThis [program](http://play.golang.org/p/1VZyzDnjND)\r\n\r\n```go\r\npackage main\r\n\r\nimport \"fmt\"\r\n\r\nfunc main() {\r\n\ta := 0.5\r\n\ta = a * 2 / 3\r\n\tfmt.Println(a)\r\n\r\n\tb := 0.5\r\n\tb *= 2 / 3\r\n\tfmt.Println(b)\r\n}\r\n```\r\n\r\nOutputs\r\n\r\n```\r\n0.3333333333333333\r\n0\r\n```\r\n\r\n(Issue originally submited by @crmackay as #11158, but closed and locked, hence resubmitting here.)"},"comment":{"url":"https://api.github.com/repos/golang/go/issues/comments/111415339","html_url":"https://github.com/golang/go/issues/11161#issuecomment-111415339","issue_url":"https://api.github.com/repos/golang/go/issues/11161","id":111415339,"user":{"login":"cznic","id":729580,"avatar_url":"https://avatars.githubusercontent.com/u/729580?v=3","gravatar_id":"","url":"https://api.github.com/users/cznic","html_url":"https://github.com/cznic","followers_url":"https://api.github.com/users/cznic/followers","following_url":"https://api.github.com/users/cznic/following{/other_user}","gists_url":"https://api.github.com/users/cznic/gists{/gist_id}","starred_url":"https://api.github.com/users/cznic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cznic/subscriptions","organizations_url":"https://api.github.com/users/cznic/orgs","repos_url":"https://api.github.com/users/cznic/repos","events_url":"https://api.github.com/users/cznic/events{/privacy}","received_events_url":"https://api.github.com/users/cznic/received_events","type":"User","site_admin":false},"created_at":"2015-06-12T08:41:11Z","updated_at":"2015-06-12T08:41:11Z","body":"@mdempsky That's a nice suggestion and I see @griesemer has already implemented it. Thanks to both of you.\r\n\r\nA side note: What tripped me in the understanding of this particular part of specs is this\r\n\r\n> Constant expressions are always evaluated exactly; ...\r\n\r\nI just stopped reading after the word *exactly*, as I automatically, but wrongly, assumed it naturaly implies arithmetic commutativity/associativity is granted for the *whole expression* - as is the case with *exact*/symbolic arithmetics, like seen in Maxima or Mathematica or any other CAS.\r\n\r\nI learned that actually the specified exactness works granularly - for every [binary] operation in particular, but then the intermediate result is possibly turned *inexact* by applying a specific domain, eg. ℤ - with the loss of arithmetic commutativity and/or associativity.\r\n\r\nI can see the reason for this difference wrt to \"ideal\" const expression evaluation and I'm fine with it.\r\n\r\nThanks again to all for the explanation."}}