{"action":"created","issue":{"url":"https://api.github.com/repos/D-Programming-Language/phobos/issues/2513","labels_url":"https://api.github.com/repos/D-Programming-Language/phobos/issues/2513/labels{/name}","comments_url":"https://api.github.com/repos/D-Programming-Language/phobos/issues/2513/comments","events_url":"https://api.github.com/repos/D-Programming-Language/phobos/issues/2513/events","html_url":"https://github.com/D-Programming-Language/phobos/pull/2513","id":42717863,"number":2513,"title":"Precise fsum","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},"labels":[{"url":"https://api.github.com/repos/D-Programming-Language/phobos/labels/blocked","name":"blocked","color":"e11d21"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2014-09-14T10:37:48Z","updated_at":"2015-02-08T11:29:59Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/2513","html_url":"https://github.com/D-Programming-Language/phobos/pull/2513","diff_url":"https://github.com/D-Programming-Language/phobos/pull/2513.diff","patch_url":"https://github.com/D-Programming-Language/phobos/pull/2513.patch"},"body":"### Not ready!\r\n\r\n### Blocked\r\n#### Issues\r\n 1. https://issues.dlang.org/show_bug.cgi?id=13485 \r\n 2. https://issues.dlang.org/show_bug.cgi?id=13474\r\n\r\nNote issue 13469 while testing:\r\nhttps://issues.dlang.org/show_bug.cgi?id=13469\r\n\r\n### TODO\r\n 0. Reorganize structure\r\n 1. CTFE (Needs CTFEScopeBuffer and #2521)\r\n 2. Summation directly in array without scopeBuffer.\r\n 3. Add links\r\n 4. Use FP Flags where possible\r\n\r\n\r\n### Example 0:\r\n```D\r\n/// For internal use only\r\nimport std.internal.math.summation;\r\nimport std.math, std.algorithm, std.range;\r\nauto r1 = iota(  1, 501 ).map!(a => (-1.0)^^a/a);\r\nauto r2 = iota(501, 1001).map!(a => (-1.0)^^a/a);\r\nSummator!double s1 = 0, s2 = 0;\r\nforeach(e; r1) s1.put(e); \r\nforeach(e; r2) s2 -= e;  //put(-e)\r\ns1 -= s2;\r\nassert(s1.sum == -0.69264743055982025);\r\n```\r\n\r\n### Example 1:\r\n```D\r\nimport std.algorithm : map;\r\nimport std.numeric : fsum;\r\nauto ar = [1, 1e100, 1, -1e100].map!(a => a*10000);\r\ndouble r = 20000;\r\nassert(r != ar.fsum!(Summation.Naive));\r\nassert(r != ar.fsum!(Summation.Pairwise));\r\nassert(r != ar.fsum!(Summation.Kahan));\r\nassert(r == ar.fsum!(Summation.KBN)); //Fails with dmd -O -m32: DMD Optimizer BUG.   :(\r\nassert(r == ar.fsum!(Summation.KB2));\r\nassert(r == ar.fsum);  //Summation.Precise\r\n```\r\n\r\n### Example 2:\r\n```D\r\n//Summation.Precise is default\r\n\r\n// Works like Python's fsum, \r\n// but  current implementation re-establish special\r\n// value semantics across iterations (i.e. handling -Inf + Inf).\r\n\r\nimport std.numeric : fsum;\r\nimport std.math, std.algorithm, std.range;\r\nauto ar = iota(1000).map!(a => 1.7.pow(a+1) - 1.7.pow(a)).chain([-(1.7.pow(1000))]);\r\nassert(ar.fsum  ==  -1.0);\r\nassert(ar.fsum!real  ==  -1.0);\r\n```"},"comment":{"url":"https://api.github.com/repos/D-Programming-Language/phobos/issues/comments/73406999","html_url":"https://github.com/D-Programming-Language/phobos/pull/2513#issuecomment-73406999","issue_url":"https://api.github.com/repos/D-Programming-Language/phobos/issues/2513","id":73406999,"user":{"login":"yebblies","id":580100,"avatar_url":"https://avatars.githubusercontent.com/u/580100?v=3","gravatar_id":"","url":"https://api.github.com/users/yebblies","html_url":"https://github.com/yebblies","followers_url":"https://api.github.com/users/yebblies/followers","following_url":"https://api.github.com/users/yebblies/following{/other_user}","gists_url":"https://api.github.com/users/yebblies/gists{/gist_id}","starred_url":"https://api.github.com/users/yebblies/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yebblies/subscriptions","organizations_url":"https://api.github.com/users/yebblies/orgs","repos_url":"https://api.github.com/users/yebblies/repos","events_url":"https://api.github.com/users/yebblies/events{/privacy}","received_events_url":"https://api.github.com/users/yebblies/received_events","type":"User","site_admin":false},"created_at":"2015-02-08T11:29:59Z","updated_at":"2015-02-08T11:29:59Z","body":"This needs rebasing."}}