{"action":"created","issue":{"url":"https://api.github.com/repos/D-Programming-Language/phobos/issues/3755","labels_url":"https://api.github.com/repos/D-Programming-Language/phobos/issues/3755/labels{/name}","comments_url":"https://api.github.com/repos/D-Programming-Language/phobos/issues/3755/comments","events_url":"https://api.github.com/repos/D-Programming-Language/phobos/issues/3755/events","html_url":"https://github.com/D-Programming-Language/phobos/pull/3755","id":112384894,"number":3755,"title":"std.math.nextPow2","user":{"login":"JackStouffer","id":680068,"avatar_url":"https://avatars.githubusercontent.com/u/680068?v=3","gravatar_id":"","url":"https://api.github.com/users/JackStouffer","html_url":"https://github.com/JackStouffer","followers_url":"https://api.github.com/users/JackStouffer/followers","following_url":"https://api.github.com/users/JackStouffer/following{/other_user}","gists_url":"https://api.github.com/users/JackStouffer/gists{/gist_id}","starred_url":"https://api.github.com/users/JackStouffer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JackStouffer/subscriptions","organizations_url":"https://api.github.com/users/JackStouffer/orgs","repos_url":"https://api.github.com/users/JackStouffer/repos","events_url":"https://api.github.com/users/JackStouffer/events{/privacy}","received_events_url":"https://api.github.com/users/JackStouffer/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/D-Programming-Language/phobos/labels/math","name":"math","color":"eb6420"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":30,"created_at":"2015-10-20T14:44:54Z","updated_at":"2015-11-05T18:09:28Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/3755","html_url":"https://github.com/D-Programming-Language/phobos/pull/3755","diff_url":"https://github.com/D-Programming-Language/phobos/pull/3755.diff","patch_url":"https://github.com/D-Programming-Language/phobos/pull/3755.patch"},"body":"https://issues.dlang.org/show_bug.cgi?id=6343\r\n\r\nAdded a new function to std.math `nextPow2`. The code here is adapted from the DDMD function, which is why it is different than the suggested code in the bug report. Also, this code is safe, as well as 11% faster.\r\n\r\nping @9il, you asked me to notify you when I made a math PR."},"comment":{"url":"https://api.github.com/repos/D-Programming-Language/phobos/issues/comments/154140940","html_url":"https://github.com/D-Programming-Language/phobos/pull/3755#issuecomment-154140940","issue_url":"https://api.github.com/repos/D-Programming-Language/phobos/issues/3755","id":154140940,"user":{"login":"9il","id":845083,"avatar_url":"https://avatars.githubusercontent.com/u/845083?v=3","gravatar_id":"","url":"https://api.github.com/users/9il","html_url":"https://github.com/9il","followers_url":"https://api.github.com/users/9il/followers","following_url":"https://api.github.com/users/9il/following{/other_user}","gists_url":"https://api.github.com/users/9il/gists{/gist_id}","starred_url":"https://api.github.com/users/9il/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/9il/subscriptions","organizations_url":"https://api.github.com/users/9il/orgs","repos_url":"https://api.github.com/users/9il/repos","events_url":"https://api.github.com/users/9il/events{/privacy}","received_events_url":"https://api.github.com/users/9il/received_events","type":"User","site_admin":false},"created_at":"2015-11-05T18:09:28Z","updated_at":"2015-11-05T18:09:28Z","body":"Excuse me for delay.\r\nSo, it can be done easily with `frexp` and `ldexp`.\r\n```D\r\nimport std.traits;\r\nimport std.math;\r\n\r\nT nextPow2(T)(const T x)\r\n    if (isFloatingPoint!T)\r\n{\r\n    if(!x.isFinite)\r\n        return x;\r\n    if(!x)\r\n    \treturn x;\r\n    int exp;\r\n    auto y = frexp(x, exp);\r\n    y = ldexp(cast(T)0.5, exp+1);\r\n    y = copysign(y, x);\r\n    return y;\r\n}\r\n\r\nunittest {\r\n\timport std.meta: AliasSeq;\r\n\tforeach(T; AliasSeq!(float, double, real))\r\n\t{\r\n\t\tenum T subNormal = T.min_normal / 2;\r\n\r\n\t\tassert(nextPow2(subNormal) == T.min_normal);\r\n\r\n\t\tassert(nextPow2(T(0.0)) == 0.0);\r\n\r\n\t\tassert(nextPow2(T(2.0)) == 4.0);\r\n\t\tassert(nextPow2(T(2.1)) == 4.0);\r\n\t\tassert(nextPow2(T(3.1)) == 4.0);\r\n\t\tassert(nextPow2(T(4.0)) == 8.0);\r\n\t\tassert(nextPow2(T(0.25)) == 0.5);\r\n\r\n\t\tassert(nextPow2(T(-2.0)) == -4.0);\r\n\t\tassert(nextPow2(T(-2.1)) == -4.0);\r\n\t\tassert(nextPow2(T(-3.1)) == -4.0);\r\n\t\tassert(nextPow2(T(-4.0)) == -8.0);\r\n\t\tassert(nextPow2(T(-0.25)) == -0.5);\r\n\r\n\t\tassert(nextPow2(T.max) == T.infinity);\r\n\t\tassert(nextPow2(-T.max) == -T.infinity);\r\n\r\n\t\tassert(nextPow2(T.infinity) == T.infinity);\r\n\t\tassert(nextPow2(T.init).isNaN);\r\n\t}\r\n}\r\n```"}}