{"action":"created","issue":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/5311","repository_url":"https://api.github.com/repos/JuliaLang/julia","labels_url":"https://api.github.com/repos/JuliaLang/julia/issues/5311/labels{/name}","comments_url":"https://api.github.com/repos/JuliaLang/julia/issues/5311/comments","events_url":"https://api.github.com/repos/JuliaLang/julia/issues/5311/events","html_url":"https://github.com/JuliaLang/julia/issues/5311","id":25070700,"number":5311,"title":"Allow to specify the result type of a sum","user":{"login":"lindahua","id":1900250,"avatar_url":"https://avatars.githubusercontent.com/u/1900250?v=3","gravatar_id":"","url":"https://api.github.com/users/lindahua","html_url":"https://github.com/lindahua","followers_url":"https://api.github.com/users/lindahua/followers","following_url":"https://api.github.com/users/lindahua/following{/other_user}","gists_url":"https://api.github.com/users/lindahua/gists{/gist_id}","starred_url":"https://api.github.com/users/lindahua/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lindahua/subscriptions","organizations_url":"https://api.github.com/users/lindahua/orgs","repos_url":"https://api.github.com/users/lindahua/repos","events_url":"https://api.github.com/users/lindahua/events{/privacy}","received_events_url":"https://api.github.com/users/lindahua/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":12,"created_at":"2014-01-05T13:27:50Z","updated_at":"2016-10-30T06:59:27Z","closed_at":null,"body":"Currently, the `sum` function use the element type (except for the boolean case) of the input array as result type. This is sometimes not a desirable choice:\n\n``` julia\nfunction mysum(R, x)\n    s = zero(R)\n    for v in x; s += v; end\n    return s\nend\n\njulia> x = uint8(rand(1:10, 50));\n\njulia> sum(x)\n0x0000000000000122\n\n# to prevent overflow\njulia> mysum(Int, x)\n290\n\njulia> a = rand(Float32, 10^6);\n\njulia> sum(float64(a)) - sum(a)\n-0.018809685949236155\n\n# to get higher accuracy\njulia> sum(float64(a)) - mysum(0.0, a)\n1.1641532182693481e-10\n```\n\nMy proposal is to add a method like `sum(R, x)` where `R` is the user-specifed type. This won't break any existing codes, but provide the user additional choices.\n"},"comment":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/comments/257135623","html_url":"https://github.com/JuliaLang/julia/issues/5311#issuecomment-257135623","issue_url":"https://api.github.com/repos/JuliaLang/julia/issues/5311","id":257135623,"user":{"login":"oscardssmith","id":11729272,"avatar_url":"https://avatars.githubusercontent.com/u/11729272?v=3","gravatar_id":"","url":"https://api.github.com/users/oscardssmith","html_url":"https://github.com/oscardssmith","followers_url":"https://api.github.com/users/oscardssmith/followers","following_url":"https://api.github.com/users/oscardssmith/following{/other_user}","gists_url":"https://api.github.com/users/oscardssmith/gists{/gist_id}","starred_url":"https://api.github.com/users/oscardssmith/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/oscardssmith/subscriptions","organizations_url":"https://api.github.com/users/oscardssmith/orgs","repos_url":"https://api.github.com/users/oscardssmith/repos","events_url":"https://api.github.com/users/oscardssmith/events{/privacy}","received_events_url":"https://api.github.com/users/oscardssmith/received_events","type":"User","site_admin":false},"created_at":"2016-10-30T06:59:27Z","updated_at":"2016-10-30T06:59:27Z","body":"Given the existence of 18423, should this be closed?"}}
{"actor":{"display_login":"oscardssmith"}}