{"action":"created","comment":{"url":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/comments/46097492","id":46097492,"diff_hunk":"@@ -4175,6 +4176,41 @@ real round(real x) @trusted nothrow @nogc\n         return core.stdc.math.roundl(x);\n }\n \n+///\n+@safe nothrow @nogc unittest\n+{\n+    assert(round(0.49) == 0);\n+    assert(round(0.5 ) == 0);\n+    assert(round(0.51) == 1);\n+    assert(round(1.5 ) == 2);\n+}\n+\n+/*******************************************\n+ * Return the value of x rounded to the given precision (number of decimal places).\n+ *\n+ * If the fractional part of x $(I below) the last required decimal place is\n+ * exactly 0.5, the last decimal place is rounded to the nearby even digit.\n+ *\n+ * The precision can be negative, in which case rounding to the nearest multiple\n+ * of positive powers of ten (10, 100 etc) will occur.\n+ */\n+real round(real val, int prec) @safe nothrow @nogc\n+{\n+    real pow = 10 ^^ prec;","path":"std/math.d","position":35,"original_position":35,"commit_id":"686ac5d9e65ecd6edc7a1ea782f5ea241ba188e5","original_commit_id":"686ac5d9e65ecd6edc7a1ea782f5ea241ba188e5","user":{"login":"tsbockman","id":1332026,"avatar_url":"https://avatars.githubusercontent.com/u/1332026?v=3","gravatar_id":"","url":"https://api.github.com/users/tsbockman","html_url":"https://github.com/tsbockman","followers_url":"https://api.github.com/users/tsbockman/followers","following_url":"https://api.github.com/users/tsbockman/following{/other_user}","gists_url":"https://api.github.com/users/tsbockman/gists{/gist_id}","starred_url":"https://api.github.com/users/tsbockman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tsbockman/subscriptions","organizations_url":"https://api.github.com/users/tsbockman/orgs","repos_url":"https://api.github.com/users/tsbockman/repos","events_url":"https://api.github.com/users/tsbockman/events{/privacy}","received_events_url":"https://api.github.com/users/tsbockman/received_events","type":"User","site_admin":false},"body":"This will easily and silently overflow, because you are computing the power with `int` arithmetic.\r\n\r\nYou need to make sure that `10` is already of type `real` *before* being fed into the power operator `^^` to avoid this. Because of [DMD issue #15288](https://issues.dlang.org/show_bug.cgi?id=15288), the obvious solution `cast(real)10 ^^ prec` won't do what you need.\r\n\r\nThe best way is this: `10.0L ^^ prec`. Adding `.0L` makes `10` into a type `real` literal, instead of the default `int`.","created_at":"2015-11-29T20:27:25Z","updated_at":"2015-11-29T20:27:25Z","html_url":"https://github.com/D-Programming-Language/phobos/pull/3759#discussion_r46097492","pull_request_url":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/3759","_links":{"self":{"href":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/comments/46097492"},"html":{"href":"https://github.com/D-Programming-Language/phobos/pull/3759#discussion_r46097492"},"pull_request":{"href":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/3759"}}},"pull_request":{"url":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/3759","id":48323738,"html_url":"https://github.com/D-Programming-Language/phobos/pull/3759","diff_url":"https://github.com/D-Programming-Language/phobos/pull/3759.diff","patch_url":"https://github.com/D-Programming-Language/phobos/pull/3759.patch","issue_url":"https://api.github.com/repos/D-Programming-Language/phobos/issues/3759","number":3759,"state":"open","locked":false,"title":"std.math: add round overload to round to a given precision","user":{"login":"jamadagni","id":948170,"avatar_url":"https://avatars.githubusercontent.com/u/948170?v=3","gravatar_id":"","url":"https://api.github.com/users/jamadagni","html_url":"https://github.com/jamadagni","followers_url":"https://api.github.com/users/jamadagni/followers","following_url":"https://api.github.com/users/jamadagni/following{/other_user}","gists_url":"https://api.github.com/users/jamadagni/gists{/gist_id}","starred_url":"https://api.github.com/users/jamadagni/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jamadagni/subscriptions","organizations_url":"https://api.github.com/users/jamadagni/orgs","repos_url":"https://api.github.com/users/jamadagni/repos","events_url":"https://api.github.com/users/jamadagni/events{/privacy}","received_events_url":"https://api.github.com/users/jamadagni/received_events","type":"User","site_admin":false},"body":"Python has this. I often find it useful. It was trivial to implement. So I submit this.","created_at":"2015-10-21T12:23:21Z","updated_at":"2015-11-29T20:27:25Z","closed_at":null,"merged_at":null,"merge_commit_sha":"223eabca89bba620ad87cb86b9f5a218b561920d","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/3759/commits","review_comments_url":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/3759/comments","review_comment_url":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/comments{/number}","comments_url":"https://api.github.com/repos/D-Programming-Language/phobos/issues/3759/comments","statuses_url":"https://api.github.com/repos/D-Programming-Language/phobos/statuses/686ac5d9e65ecd6edc7a1ea782f5ea241ba188e5","head":{"label":"jamadagni:math_round_prec","ref":"math_round_prec","sha":"686ac5d9e65ecd6edc7a1ea782f5ea241ba188e5","user":{"login":"jamadagni","id":948170,"avatar_url":"https://avatars.githubusercontent.com/u/948170?v=3","gravatar_id":"","url":"https://api.github.com/users/jamadagni","html_url":"https://github.com/jamadagni","followers_url":"https://api.github.com/users/jamadagni/followers","following_url":"https://api.github.com/users/jamadagni/following{/other_user}","gists_url":"https://api.github.com/users/jamadagni/gists{/gist_id}","starred_url":"https://api.github.com/users/jamadagni/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jamadagni/subscriptions","organizations_url":"https://api.github.com/users/jamadagni/orgs","repos_url":"https://api.github.com/users/jamadagni/repos","events_url":"https://api.github.com/users/jamadagni/events{/privacy}","received_events_url":"https://api.github.com/users/jamadagni/received_events","type":"User","site_admin":false},"repo":{"id":44473888,"name":"phobos","full_name":"jamadagni/phobos","owner":{"login":"jamadagni","id":948170,"avatar_url":"https://avatars.githubusercontent.com/u/948170?v=3","gravatar_id":"","url":"https://api.github.com/users/jamadagni","html_url":"https://github.com/jamadagni","followers_url":"https://api.github.com/users/jamadagni/followers","following_url":"https://api.github.com/users/jamadagni/following{/other_user}","gists_url":"https://api.github.com/users/jamadagni/gists{/gist_id}","starred_url":"https://api.github.com/users/jamadagni/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jamadagni/subscriptions","organizations_url":"https://api.github.com/users/jamadagni/orgs","repos_url":"https://api.github.com/users/jamadagni/repos","events_url":"https://api.github.com/users/jamadagni/events{/privacy}","received_events_url":"https://api.github.com/users/jamadagni/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jamadagni/phobos","description":"The standard library of the D programming language","fork":true,"url":"https://api.github.com/repos/jamadagni/phobos","forks_url":"https://api.github.com/repos/jamadagni/phobos/forks","keys_url":"https://api.github.com/repos/jamadagni/phobos/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jamadagni/phobos/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jamadagni/phobos/teams","hooks_url":"https://api.github.com/repos/jamadagni/phobos/hooks","issue_events_url":"https://api.github.com/repos/jamadagni/phobos/issues/events{/number}","events_url":"https://api.github.com/repos/jamadagni/phobos/events","assignees_url":"https://api.github.com/repos/jamadagni/phobos/assignees{/user}","branches_url":"https://api.github.com/repos/jamadagni/phobos/branches{/branch}","tags_url":"https://api.github.com/repos/jamadagni/phobos/tags","blobs_url":"https://api.github.com/repos/jamadagni/phobos/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jamadagni/phobos/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jamadagni/phobos/git/refs{/sha}","trees_url":"https://api.github.com/repos/jamadagni/phobos/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jamadagni/phobos/statuses/{sha}","languages_url":"https://api.github.com/repos/jamadagni/phobos/languages","stargazers_url":"https://api.github.com/repos/jamadagni/phobos/stargazers","contributors_url":"https://api.github.com/repos/jamadagni/phobos/contributors","subscribers_url":"https://api.github.com/repos/jamadagni/phobos/subscribers","subscription_url":"https://api.github.com/repos/jamadagni/phobos/subscription","commits_url":"https://api.github.com/repos/jamadagni/phobos/commits{/sha}","git_commits_url":"https://api.github.com/repos/jamadagni/phobos/git/commits{/sha}","comments_url":"https://api.github.com/repos/jamadagni/phobos/comments{/number}","issue_comment_url":"https://api.github.com/repos/jamadagni/phobos/issues/comments{/number}","contents_url":"https://api.github.com/repos/jamadagni/phobos/contents/{+path}","compare_url":"https://api.github.com/repos/jamadagni/phobos/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jamadagni/phobos/merges","archive_url":"https://api.github.com/repos/jamadagni/phobos/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jamadagni/phobos/downloads","issues_url":"https://api.github.com/repos/jamadagni/phobos/issues{/number}","pulls_url":"https://api.github.com/repos/jamadagni/phobos/pulls{/number}","milestones_url":"https://api.github.com/repos/jamadagni/phobos/milestones{/number}","notifications_url":"https://api.github.com/repos/jamadagni/phobos/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jamadagni/phobos/labels{/name}","releases_url":"https://api.github.com/repos/jamadagni/phobos/releases{/id}","created_at":"2015-10-18T10:29:19Z","updated_at":"2015-10-18T10:29:29Z","pushed_at":"2015-10-23T10:16:55Z","git_url":"git://github.com/jamadagni/phobos.git","ssh_url":"git@github.com:jamadagni/phobos.git","clone_url":"https://github.com/jamadagni/phobos.git","svn_url":"https://github.com/jamadagni/phobos","homepage":"dlang.org/phobos","size":46217,"stargazers_count":0,"watchers_count":0,"language":"D","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"D-Programming-Language:master","ref":"master","sha":"48701fcd1f7f94ad0f8f84a710a2507bd81d68da","user":{"login":"D-Programming-Language","id":565913,"avatar_url":"https://avatars.githubusercontent.com/u/565913?v=3","gravatar_id":"","url":"https://api.github.com/users/D-Programming-Language","html_url":"https://github.com/D-Programming-Language","followers_url":"https://api.github.com/users/D-Programming-Language/followers","following_url":"https://api.github.com/users/D-Programming-Language/following{/other_user}","gists_url":"https://api.github.com/users/D-Programming-Language/gists{/gist_id}","starred_url":"https://api.github.com/users/D-Programming-Language/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/D-Programming-Language/subscriptions","organizations_url":"https://api.github.com/users/D-Programming-Language/orgs","repos_url":"https://api.github.com/users/D-Programming-Language/repos","events_url":"https://api.github.com/users/D-Programming-Language/events{/privacy}","received_events_url":"https://api.github.com/users/D-Programming-Language/received_events","type":"Organization","site_admin":false},"repo":{"id":1257084,"name":"phobos","full_name":"D-Programming-Language/phobos","owner":{"login":"D-Programming-Language","id":565913,"avatar_url":"https://avatars.githubusercontent.com/u/565913?v=3","gravatar_id":"","url":"https://api.github.com/users/D-Programming-Language","html_url":"https://github.com/D-Programming-Language","followers_url":"https://api.github.com/users/D-Programming-Language/followers","following_url":"https://api.github.com/users/D-Programming-Language/following{/other_user}","gists_url":"https://api.github.com/users/D-Programming-Language/gists{/gist_id}","starred_url":"https://api.github.com/users/D-Programming-Language/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/D-Programming-Language/subscriptions","organizations_url":"https://api.github.com/users/D-Programming-Language/orgs","repos_url":"https://api.github.com/users/D-Programming-Language/repos","events_url":"https://api.github.com/users/D-Programming-Language/events{/privacy}","received_events_url":"https://api.github.com/users/D-Programming-Language/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/D-Programming-Language/phobos","description":"The standard library of the D programming language","fork":false,"url":"https://api.github.com/repos/D-Programming-Language/phobos","forks_url":"https://api.github.com/repos/D-Programming-Language/phobos/forks","keys_url":"https://api.github.com/repos/D-Programming-Language/phobos/keys{/key_id}","collaborators_url":"https://api.github.com/repos/D-Programming-Language/phobos/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/D-Programming-Language/phobos/teams","hooks_url":"https://api.github.com/repos/D-Programming-Language/phobos/hooks","issue_events_url":"https://api.github.com/repos/D-Programming-Language/phobos/issues/events{/number}","events_url":"https://api.github.com/repos/D-Programming-Language/phobos/events","assignees_url":"https://api.github.com/repos/D-Programming-Language/phobos/assignees{/user}","branches_url":"https://api.github.com/repos/D-Programming-Language/phobos/branches{/branch}","tags_url":"https://api.github.com/repos/D-Programming-Language/phobos/tags","blobs_url":"https://api.github.com/repos/D-Programming-Language/phobos/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/D-Programming-Language/phobos/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/D-Programming-Language/phobos/git/refs{/sha}","trees_url":"https://api.github.com/repos/D-Programming-Language/phobos/git/trees{/sha}","statuses_url":"https://api.github.com/repos/D-Programming-Language/phobos/statuses/{sha}","languages_url":"https://api.github.com/repos/D-Programming-Language/phobos/languages","stargazers_url":"https://api.github.com/repos/D-Programming-Language/phobos/stargazers","contributors_url":"https://api.github.com/repos/D-Programming-Language/phobos/contributors","subscribers_url":"https://api.github.com/repos/D-Programming-Language/phobos/subscribers","subscription_url":"https://api.github.com/repos/D-Programming-Language/phobos/subscription","commits_url":"https://api.github.com/repos/D-Programming-Language/phobos/commits{/sha}","git_commits_url":"https://api.github.com/repos/D-Programming-Language/phobos/git/commits{/sha}","comments_url":"https://api.github.com/repos/D-Programming-Language/phobos/comments{/number}","issue_comment_url":"https://api.github.com/repos/D-Programming-Language/phobos/issues/comments{/number}","contents_url":"https://api.github.com/repos/D-Programming-Language/phobos/contents/{+path}","compare_url":"https://api.github.com/repos/D-Programming-Language/phobos/compare/{base}...{head}","merges_url":"https://api.github.com/repos/D-Programming-Language/phobos/merges","archive_url":"https://api.github.com/repos/D-Programming-Language/phobos/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/D-Programming-Language/phobos/downloads","issues_url":"https://api.github.com/repos/D-Programming-Language/phobos/issues{/number}","pulls_url":"https://api.github.com/repos/D-Programming-Language/phobos/pulls{/number}","milestones_url":"https://api.github.com/repos/D-Programming-Language/phobos/milestones{/number}","notifications_url":"https://api.github.com/repos/D-Programming-Language/phobos/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/D-Programming-Language/phobos/labels{/name}","releases_url":"https://api.github.com/repos/D-Programming-Language/phobos/releases{/id}","created_at":"2011-01-15T07:00:06Z","updated_at":"2015-11-22T16:02:39Z","pushed_at":"2015-11-29T20:02:41Z","git_url":"git://github.com/D-Programming-Language/phobos.git","ssh_url":"git@github.com:D-Programming-Language/phobos.git","clone_url":"https://github.com/D-Programming-Language/phobos.git","svn_url":"https://github.com/D-Programming-Language/phobos","homepage":"dlang.org/phobos","size":68939,"stargazers_count":654,"watchers_count":654,"language":"D","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":431,"mirror_url":null,"open_issues_count":67,"forks":431,"open_issues":67,"watchers":654,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/3759"},"html":{"href":"https://github.com/D-Programming-Language/phobos/pull/3759"},"issue":{"href":"https://api.github.com/repos/D-Programming-Language/phobos/issues/3759"},"comments":{"href":"https://api.github.com/repos/D-Programming-Language/phobos/issues/3759/comments"},"review_comments":{"href":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/3759/comments"},"review_comment":{"href":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/3759/commits"},"statuses":{"href":"https://api.github.com/repos/D-Programming-Language/phobos/statuses/686ac5d9e65ecd6edc7a1ea782f5ea241ba188e5"}}}}