{"action":"created","issue":{"url":"https://api.github.com/repos/ceylon/ceylon/issues/5799","repository_url":"https://api.github.com/repos/ceylon/ceylon","labels_url":"https://api.github.com/repos/ceylon/ceylon/issues/5799/labels{/name}","comments_url":"https://api.github.com/repos/ceylon/ceylon/issues/5799/comments","events_url":"https://api.github.com/repos/ceylon/ceylon/issues/5799/events","html_url":"https://github.com/ceylon/ceylon/issues/5799","id":120871558,"number":5799,"title":"JS: always truncate to 32bits on bitwise operations","user":{"login":"jvasileff","id":236050,"avatar_url":"https://avatars.githubusercontent.com/u/236050?v=3","gravatar_id":"","url":"https://api.github.com/users/jvasileff","html_url":"https://github.com/jvasileff","followers_url":"https://api.github.com/users/jvasileff/followers","following_url":"https://api.github.com/users/jvasileff/following{/other_user}","gists_url":"https://api.github.com/users/jvasileff/gists{/gist_id}","starred_url":"https://api.github.com/users/jvasileff/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jvasileff/subscriptions","organizations_url":"https://api.github.com/users/jvasileff/orgs","repos_url":"https://api.github.com/users/jvasileff/repos","events_url":"https://api.github.com/users/jvasileff/events{/privacy}","received_events_url":"https://api.github.com/users/jvasileff/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/ceylon/ceylon/labels/m-compiler-js","name":"m-compiler-js","color":"00aa00"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/ceylon/ceylon/milestones/15","html_url":"https://github.com/ceylon/ceylon/milestones/1.2.3","labels_url":"https://api.github.com/repos/ceylon/ceylon/milestones/15/labels","id":1590811,"number":15,"title":"1.2.3","description":"","creator":{"login":"FroMage","id":179265,"avatar_url":"https://avatars.githubusercontent.com/u/179265?v=3","gravatar_id":"","url":"https://api.github.com/users/FroMage","html_url":"https://github.com/FroMage","followers_url":"https://api.github.com/users/FroMage/followers","following_url":"https://api.github.com/users/FroMage/following{/other_user}","gists_url":"https://api.github.com/users/FroMage/gists{/gist_id}","starred_url":"https://api.github.com/users/FroMage/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/FroMage/subscriptions","organizations_url":"https://api.github.com/users/FroMage/orgs","repos_url":"https://api.github.com/users/FroMage/repos","events_url":"https://api.github.com/users/FroMage/events{/privacy}","received_events_url":"https://api.github.com/users/FroMage/received_events","type":"User","site_admin":false},"open_issues":175,"closed_issues":151,"state":"open","created_at":"2016-02-18T14:05:01Z","updated_at":"2016-06-08T21:42:06Z","due_on":null,"closed_at":null},"comments":6,"created_at":"2015-12-07T21:26:41Z","updated_at":"2016-06-09T17:39:47Z","closed_at":null,"body":"Bitwise operations in JS produce results truncated to 32 bits. But, this doesn't happen for `Binary.set(index)`, `clear`, and `flip` when `index` is out of range.\r\n\r\nGiven that code calling one of these methods must have been written with the intention of using 32 bit values, I believe it would be correct to perform the truncation regardless of the `index`. This can be done by or'ing with 0 `i | 0` (which, btw, demonstrates that even \"noop\" bitwise operations in JS truncate.)\r\n\r\nCurrently, we have:\r\n\r\n```ceylon\r\n    value big=#100000000;\r\n    print (big.clear(-1)); // 4294967296\r\n    print (big.clear(0));  // 0\r\n    print (big.clear(31)); // 0\r\n    print (big.clear(32)); // 4294967296\r\n```\r\n\r\nwith he proposed change, all results would be 0.\r\n\r\nI believe this would be consistent with the current documentation for `set()`:\r\n\r\n> Returns an instance with the given bit set to the given value if 0 <= index < size, otherwise returns a value with the same bits as this value.\r\n\r\nsince it is claimed a value with the same *bits* will be returned, not necessarily the same value, addressable bits or otherwise."},"comment":{"url":"https://api.github.com/repos/ceylon/ceylon/issues/comments/224970595","html_url":"https://github.com/ceylon/ceylon/issues/5799#issuecomment-224970595","issue_url":"https://api.github.com/repos/ceylon/ceylon/issues/5799","id":224970595,"user":{"login":"chochos","id":17679,"avatar_url":"https://avatars.githubusercontent.com/u/17679?v=3","gravatar_id":"","url":"https://api.github.com/users/chochos","html_url":"https://github.com/chochos","followers_url":"https://api.github.com/users/chochos/followers","following_url":"https://api.github.com/users/chochos/following{/other_user}","gists_url":"https://api.github.com/users/chochos/gists{/gist_id}","starred_url":"https://api.github.com/users/chochos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chochos/subscriptions","organizations_url":"https://api.github.com/users/chochos/orgs","repos_url":"https://api.github.com/users/chochos/repos","events_url":"https://api.github.com/users/chochos/events{/privacy}","received_events_url":"https://api.github.com/users/chochos/received_events","type":"User","site_admin":false},"created_at":"2016-06-09T17:39:47Z","updated_at":"2016-06-09T17:39:47Z","body":"And `2147483648|0` gives you `-2147483648`"}}
{"actor":{"display_login":"chochos"}}