{"action":"created","issue":{"url":"https://api.github.com/repos/bos/aeson/issues/369","repository_url":"https://api.github.com/repos/bos/aeson","labels_url":"https://api.github.com/repos/bos/aeson/issues/369/labels{/name}","comments_url":"https://api.github.com/repos/bos/aeson/issues/369/comments","events_url":"https://api.github.com/repos/bos/aeson/issues/369/events","html_url":"https://github.com/bos/aeson/issues/369","id":138747046,"number":369,"title":"Number is not normalized before encode","user":{"login":"notogawa","id":372530,"avatar_url":"https://avatars.githubusercontent.com/u/372530?v=3","gravatar_id":"","url":"https://api.github.com/users/notogawa","html_url":"https://github.com/notogawa","followers_url":"https://api.github.com/users/notogawa/followers","following_url":"https://api.github.com/users/notogawa/following{/other_user}","gists_url":"https://api.github.com/users/notogawa/gists{/gist_id}","starred_url":"https://api.github.com/users/notogawa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/notogawa/subscriptions","organizations_url":"https://api.github.com/users/notogawa/orgs","repos_url":"https://api.github.com/users/notogawa/repos","events_url":"https://api.github.com/users/notogawa/events{/privacy}","received_events_url":"https://api.github.com/users/notogawa/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/bos/aeson/labels/enhancement","name":"enhancement","color":"207de5"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-03-06T03:03:18Z","updated_at":"2016-03-10T12:11:42Z","closed_at":"2016-03-10T12:02:20Z","body":"0 has decimal part like 0.0, when convert floating point number (Float, Double) 0 to JSON and then encode it. Other floating point numbers which have no decimal part have no decimal part. I think 0 should be 0, not 0.0, in the same way as others.\r\n\r\n~~~~\r\n> encode $ toJSON ([0,1,2,0] :: [Scientific])\r\n\"[0,1,2,0]\"\r\n> encode $ toJSON ([0,1,2,0] :: [Double])\r\n\"[0.0,1,2,0.0]\"\r\n~~~~\r\n\r\nA `base10Exponent` of Scientific value converted from floating point number 1,2,... is 0.\r\n\r\n~~~~\r\n> let n = fromFloatDigits (1 :: Double)\r\n> n\r\n1.0\r\n> coefficient n\r\n1\r\n> base10Exponent n\r\n0\r\n~~~~\r\n\r\nIn the case 0, `base10Exponent` is -1. Scientific value converted from floating point 0 is not normalized.\r\nScientific says its internal expression is not necessarily normalized.\r\n\r\n~~~~\r\n> let z = fromFloatDigits (0 :: Double)\r\n> z\r\n0.0\r\n> coefficient z\r\n0\r\n> base10Exponent z\r\n-1\r\n~~~~\r\n\r\nSo, when use internal expression like `coefficient` and `base10Exponent`, `Scientific.normalize` is required as preprocessing.\r\n\r\n~~~~\r\n> let x = normalize z\r\n> x\r\n0.0\r\n> coefficient x\r\n0\r\n> base10Exponent x\r\n0\r\n~~~~\r\n\r\nEspecially, current `Data.Aeson.Encode.Builder.number` implicitly assumes that the argument value is already normalized."},"comment":{"url":"https://api.github.com/repos/bos/aeson/issues/comments/194815573","html_url":"https://github.com/bos/aeson/issues/369#issuecomment-194815573","issue_url":"https://api.github.com/repos/bos/aeson/issues/369","id":194815573,"user":{"login":"basvandijk","id":576355,"avatar_url":"https://avatars.githubusercontent.com/u/576355?v=3","gravatar_id":"","url":"https://api.github.com/users/basvandijk","html_url":"https://github.com/basvandijk","followers_url":"https://api.github.com/users/basvandijk/followers","following_url":"https://api.github.com/users/basvandijk/following{/other_user}","gists_url":"https://api.github.com/users/basvandijk/gists{/gist_id}","starred_url":"https://api.github.com/users/basvandijk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/basvandijk/subscriptions","organizations_url":"https://api.github.com/users/basvandijk/orgs","repos_url":"https://api.github.com/users/basvandijk/repos","events_url":"https://api.github.com/users/basvandijk/events{/privacy}","received_events_url":"https://api.github.com/users/basvandijk/received_events","type":"User","site_admin":false},"created_at":"2016-03-10T12:11:42Z","updated_at":"2016-03-10T12:11:42Z","body":"I released [scientific-0.3.4.6](http://hackage.haskell.org/package/scientific-0.3.4.6) with my proposed change."}}