{"action":"opened","issue":{"url":"https://api.github.com/repos/Lixquid/atom-calc/issues/5","repository_url":"https://api.github.com/repos/Lixquid/atom-calc","labels_url":"https://api.github.com/repos/Lixquid/atom-calc/issues/5/labels{/name}","comments_url":"https://api.github.com/repos/Lixquid/atom-calc/issues/5/comments","events_url":"https://api.github.com/repos/Lixquid/atom-calc/issues/5/events","html_url":"https://github.com/Lixquid/atom-calc/issues/5","id":235052394,"number":5,"title":"JavaScript based rounding errors","user":{"login":"HatScripts","id":5691865,"avatar_url":"https://avatars2.githubusercontent.com/u/5691865?v=3","gravatar_id":"","url":"https://api.github.com/users/HatScripts","html_url":"https://github.com/HatScripts","followers_url":"https://api.github.com/users/HatScripts/followers","following_url":"https://api.github.com/users/HatScripts/following{/other_user}","gists_url":"https://api.github.com/users/HatScripts/gists{/gist_id}","starred_url":"https://api.github.com/users/HatScripts/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HatScripts/subscriptions","organizations_url":"https://api.github.com/users/HatScripts/orgs","repos_url":"https://api.github.com/users/HatScripts/repos","events_url":"https://api.github.com/users/HatScripts/events{/privacy}","received_events_url":"https://api.github.com/users/HatScripts/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-06-11T08:50:14Z","updated_at":"2017-06-11T08:50:14Z","closed_at":null,"body":"Hi, I noticed that the same rounding errors that are prevalent in JavaScript occur when using Calc in Atom.\r\n\r\n_Subtraction_ examples:\r\n```js\r\n1-0.01 = 0.99\r\n1-0.02 = 0.98\r\n1-0.03 = 0.97\r\n1-0.04 = 0.96\r\n1-0.05 = 0.95\r\n1-0.06 = 0.94\r\n1-0.07 = 0.9299999999999999\r\n1-0.08 = 0.92\r\n1-0.09 = 0.91\r\n1-0.10 = 0.9\r\n1-0.11 = 0.89\r\n1-0.12 = 0.88\r\n1-0.13 = 0.87\r\n1-0.14 = 0.86\r\n1-0.15 = 0.85\r\n1-0.16 = 0.84\r\n1-0.17 = 0.83\r\n1-0.18 = 0.8200000000000001\r\n1-0.19 = 0.81\r\n1-0.20 = 0.8\r\n1-0.21 = 0.79\r\n1-0.22 = 0.78\r\n1-0.23 = 0.77\r\n1-0.24 = 0.76\r\n1-0.25 = 0.75\r\n1-0.26 = 0.74\r\n1-0.27 = 0.73\r\n1-0.28 = 0.72\r\n1-0.29 = 0.71\r\n1-0.30 = 0.7\r\n1-0.31 = 0.69\r\n1-0.32 = 0.6799999999999999\r\n1-0.33 = 0.6699999999999999\r\n1-0.34 = 0.6599999999999999\r\n1-0.35 = 0.65\r\n1-0.36 = 0.64\r\n1-0.37 = 0.63\r\n1-0.38 = 0.62\r\n1-0.39 = 0.61\r\n1-0.40 = 0.6\r\n1-0.41 = 0.5900000000000001\r\n1-0.42 = 0.5800000000000001\r\n1-0.43 = 0.5700000000000001\r\n1-0.44 = 0.56\r\n1-0.45 = 0.55\r\n1-0.46 = 0.54\r\n1-0.47 = 0.53\r\n1-0.48 = 0.52\r\n1-0.49 = 0.51\r\n1-0.50 = 0.5\r\n1-0.51 = 0.49\r\n1-0.52 = 0.48\r\n1-0.53 = 0.47\r\n1-0.54 = 0.45999999999999996\r\n1-0.55 = 0.44999999999999996\r\n1-0.56 = 0.43999999999999995\r\n1-0.57 = 0.43000000000000005\r\n1-0.58 = 0.42000000000000004\r\n1-0.59 = 0.41000000000000003\r\n1-0.60 = 0.4\r\n1-0.61 = 0.39\r\n1-0.62 = 0.38\r\n1-0.63 = 0.37\r\n1-0.64 = 0.36\r\n1-0.65 = 0.35\r\n1-0.66 = 0.33999999999999997\r\n1-0.67 = 0.32999999999999996\r\n1-0.68 = 0.31999999999999995\r\n1-0.69 = 0.31000000000000005\r\n1-0.70 = 0.30000000000000004\r\n1-0.71 = 0.29000000000000004\r\n1-0.72 = 0.28\r\n1-0.73 = 0.27\r\n1-0.74 = 0.26\r\n1-0.75 = 0.25\r\n1-0.76 = 0.24\r\n1-0.77 = 0.22999999999999998\r\n1-0.78 = 0.21999999999999997\r\n1-0.79 = 0.20999999999999996\r\n1-0.80 = 0.19999999999999996\r\n1-0.81 = 0.18999999999999995\r\n1-0.82 = 0.18000000000000005\r\n1-0.83 = 0.17000000000000004\r\n1-0.84 = 0.16000000000000003\r\n1-0.85 = 0.15000000000000002\r\n1-0.86 = 0.14\r\n1-0.87 = 0.13\r\n1-0.88 = 0.12\r\n1-0.89 = 0.10999999999999999\r\n1-0.90 = 0.09999999999999998\r\n1-0.91 = 0.08999999999999997\r\n1-0.92 = 0.07999999999999996\r\n1-0.93 = 0.06999999999999995\r\n1-0.94 = 0.06000000000000005\r\n1-0.95 = 0.050000000000000044\r\n1-0.96 = 0.040000000000000036\r\n1-0.97 = 0.030000000000000027\r\n1-0.98 = 0.020000000000000018\r\n1-0.99 = 0.010000000000000009\r\n1-1.00 = 0\r\n```\r\n\r\nAnd a couple of examples with **division**:\r\n```js\r\n1.33/0.35 = 3.8000000000000003\r\n1.48/1.60 = 0.9249999999999999\r\n```\r\n\r\nOf course, this is no real fault of Calc. The same results (with rounding errors) are returned in the JavaScript console. However, most(?) of these rounding errors can be accounted for.\r\n\r\nIn the case of _subtraction_, subtracting a number with `n` or fewer decimal places from a number with `n` or fewer decimal places should never result in a number with over `n` decimal places.\r\n\r\nThat same logic doesn't apply with **division** of course, with the countless results that (correctly) have infinitely recurring decimal places.\r\n\r\nI did notice @dslpp056193's [pull request](/Lixquid/atom-calc/pull/3) for cutting all return values down to 2 decimals, and while that would be useful for handling the **division** results I mentioned that have infinite decimal places, for _subtraction_ results (`1 - 0.059 = 0.9410000000000001`, `1 - 0.061 = 0.9390000000000001`, etc.) it would be giving \"wrong\" results. To clarify, I think it's fine to truncate the decimal places of **division** results that infinitely recur down to 2, but 99% of the time you would want _subtraction_ results to just give the straight-up correct answer—`1 - 0.059 = 0.941 (not 0.94)`, `1 - 0.061 = 0.939 (not 0.93 or 0.94)`, etc."}}
{"actor":{"display_login":"HatScripts"}}