{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/10184","repository_url":"https://api.github.com/repos/rust-lang/rust","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/10184/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/10184/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/10184/events","html_url":"https://github.com/rust-lang/rust/issues/10184","id":21869137,"number":10184,"title":"floating point to integer casts can cause undefined behaviour","user":{"login":"thestinger","id":1505226,"avatar_url":"https://avatars2.githubusercontent.com/u/1505226?v=3","gravatar_id":"","url":"https://api.github.com/users/thestinger","html_url":"https://github.com/thestinger","followers_url":"https://api.github.com/users/thestinger/followers","following_url":"https://api.github.com/users/thestinger/following{/other_user}","gists_url":"https://api.github.com/users/thestinger/gists{/gist_id}","starred_url":"https://api.github.com/users/thestinger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thestinger/subscriptions","organizations_url":"https://api.github.com/users/thestinger/orgs","repos_url":"https://api.github.com/users/thestinger/repos","events_url":"https://api.github.com/users/thestinger/events{/privacy}","received_events_url":"https://api.github.com/users/thestinger/received_events","type":"User","site_admin":false},"labels":[{"id":289259951,"url":"https://api.github.com/repos/rust-lang/rust/labels/E-help-wanted","name":"E-help-wanted","color":"02E10C","default":false},{"id":267612997,"url":"https://api.github.com/repos/rust-lang/rust/labels/I-unsound","name":"I-unsound","color":"e11d21","default":false},{"id":100521,"url":"https://api.github.com/repos/rust-lang/rust/labels/I-wrong","name":"I-wrong","color":"e10c02","default":false},{"id":60344715,"url":"https://api.github.com/repos/rust-lang/rust/labels/P-medium","name":"P-medium","color":"eb6420","default":false},{"id":211668100,"url":"https://api.github.com/repos/rust-lang/rust/labels/T-compiler","name":"T-compiler","color":"bfd4f2","default":false},{"id":211668019,"url":"https://api.github.com/repos/rust-lang/rust/labels/T-lang","name":"T-lang","color":"bfd4f2","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":65,"created_at":"2013-10-31T00:18:33Z","updated_at":"2017-06-14T21:07:06Z","closed_at":null,"body":"**UPDATE (by @nikomatsakis):** After much discussion, we've got [the rudiments of a plan](https://github.com/rust-lang/rust/issues/10184#issuecomment-302198137) for how to address this problem. But we need some help with actually investigating the performance impact and working out the final details!\r\n\r\n----\r\n\r\n**ORIGINAL ISSUE FOLLOWS:**\r\n\r\n> If the value cannot fit in ty2, the results are undefined.\r\n\r\n``` rust\r\n1.04E+17 as u8\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/308558398","html_url":"https://github.com/rust-lang/rust/issues/10184#issuecomment-308558398","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/10184","id":308558398,"user":{"login":"simonbyrne","id":1692009,"avatar_url":"https://avatars0.githubusercontent.com/u/1692009?v=3","gravatar_id":"","url":"https://api.github.com/users/simonbyrne","html_url":"https://github.com/simonbyrne","followers_url":"https://api.github.com/users/simonbyrne/followers","following_url":"https://api.github.com/users/simonbyrne/following{/other_user}","gists_url":"https://api.github.com/users/simonbyrne/gists{/gist_id}","starred_url":"https://api.github.com/users/simonbyrne/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/simonbyrne/subscriptions","organizations_url":"https://api.github.com/users/simonbyrne/orgs","repos_url":"https://api.github.com/users/simonbyrne/repos","events_url":"https://api.github.com/users/simonbyrne/events{/privacy}","received_events_url":"https://api.github.com/users/simonbyrne/received_events","type":"User","site_admin":false},"created_at":"2017-06-14T21:07:06Z","updated_at":"2017-06-14T21:07:06Z","body":"I'm a Julia developer, and I've been following this issue for a while, as we share the same LLVM backend and so have similar issues. In case it's of interest, here is what we have settled on (with approximate timings for a single function on my machine):\r\n* `unsafe_trunc(Int64, x)` maps directly to the corresponding LLVM intrinsic `fptosi` (1.5 ns)\r\n* `trunc(Int64, x)` throws an exception for out of range values (3 ns)\r\n* `convert(Int64, x)` throws an exception for out of range or non-integer values (6 ns)\r\n\r\nAlso, I have [asked on the mailing list](http://lists.llvm.org/pipermail/llvm-dev/2016-January/094405.html) about making the undefined behaviour a little more defined, but did not receive a very promising response."}}
{"actor":{"display_login":"simonbyrne"}}