{"action":"created","issue":{"url":"https://api.github.com/repos/ccgus/fmdb/issues/501","repository_url":"https://api.github.com/repos/ccgus/fmdb","labels_url":"https://api.github.com/repos/ccgus/fmdb/issues/501/labels{/name}","comments_url":"https://api.github.com/repos/ccgus/fmdb/issues/501/comments","events_url":"https://api.github.com/repos/ccgus/fmdb/issues/501/events","html_url":"https://github.com/ccgus/fmdb/issues/501","id":158920396,"number":501,"title":"`NSDecimalNumber` lose accuracy when converted to `doubleValue`","user":{"login":"liuyaodong","id":2288732,"avatar_url":"https://avatars.githubusercontent.com/u/2288732?v=3","gravatar_id":"","url":"https://api.github.com/users/liuyaodong","html_url":"https://github.com/liuyaodong","followers_url":"https://api.github.com/users/liuyaodong/followers","following_url":"https://api.github.com/users/liuyaodong/following{/other_user}","gists_url":"https://api.github.com/users/liuyaodong/gists{/gist_id}","starred_url":"https://api.github.com/users/liuyaodong/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/liuyaodong/subscriptions","organizations_url":"https://api.github.com/users/liuyaodong/orgs","repos_url":"https://api.github.com/users/liuyaodong/repos","events_url":"https://api.github.com/users/liuyaodong/events{/privacy}","received_events_url":"https://api.github.com/users/liuyaodong/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-06-07T13:17:18Z","updated_at":"2016-06-08T04:47:04Z","closed_at":null,"body":"`FMDatabase` convert `NSNumber` to its `doubleValue` in `-bindObject:toColumn:inStatement:` when its `objCType` is double, as the code below shows:\r\n```objectivec\r\n        else if (strcmp([obj objCType], @encode(double)) == 0) {\r\n            sqlite3_bind_double(pStmt, idx, [obj doubleValue]);\r\n        }\r\n```\r\nHowever, there is a potential to lose accuracy, because `NSNumber` may actually be an instance of `NSDecimalNumber`, as the document of `NSDecimalNumber` says that `doubleValue` just \"return an approximate double value\".\r\n\r\nFor example, \r\n```objectivec\r\n    NSNumber *number = [NSDecimalNumber numberWithUnsignedLongLong:18446744073709551612ULL];\r\n    NSLog(@\"double value: %lf, unsigned long long value: %llu\",  [number doubleValue], [number unsignedLongLongValue]);\r\n```\r\nThe result will be: \"double value: 18446744073709551616.000000, unsigned long long value: 18446744073709551612\""},"comment":{"url":"https://api.github.com/repos/ccgus/fmdb/issues/comments/224486051","html_url":"https://github.com/ccgus/fmdb/issues/501#issuecomment-224486051","issue_url":"https://api.github.com/repos/ccgus/fmdb/issues/501","id":224486051,"user":{"login":"liuyaodong","id":2288732,"avatar_url":"https://avatars.githubusercontent.com/u/2288732?v=3","gravatar_id":"","url":"https://api.github.com/users/liuyaodong","html_url":"https://github.com/liuyaodong","followers_url":"https://api.github.com/users/liuyaodong/followers","following_url":"https://api.github.com/users/liuyaodong/following{/other_user}","gists_url":"https://api.github.com/users/liuyaodong/gists{/gist_id}","starred_url":"https://api.github.com/users/liuyaodong/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/liuyaodong/subscriptions","organizations_url":"https://api.github.com/users/liuyaodong/orgs","repos_url":"https://api.github.com/users/liuyaodong/repos","events_url":"https://api.github.com/users/liuyaodong/events{/privacy}","received_events_url":"https://api.github.com/users/liuyaodong/received_events","type":"User","site_admin":false},"created_at":"2016-06-08T04:47:04Z","updated_at":"2016-06-08T04:47:04Z","body":"Because when parsing JSON which contains a very big u_int64 using `NSJSONSerialization`, the result will be stored in a `NSDecimalNumber`. FMDB store `NSDecimalNumber` by looking for its `doubleValue`, thus loses accuracy."}}
{"actor":{"display_login":"liuyaodong"}}