{"action":"created","issue":{"url":"https://api.github.com/repos/OmniLayer/omnicore/issues/23","labels_url":"https://api.github.com/repos/OmniLayer/omnicore/issues/23/labels{/name}","comments_url":"https://api.github.com/repos/OmniLayer/omnicore/issues/23/comments","events_url":"https://api.github.com/repos/OmniLayer/omnicore/issues/23/events","html_url":"https://github.com/OmniLayer/omnicore/issues/23","id":70137588,"number":23,"title":"Potential loss of precision due to floating-point numbers","user":{"login":"dexX7","id":5836089,"avatar_url":"https://avatars.githubusercontent.com/u/5836089?v=3","gravatar_id":"","url":"https://api.github.com/users/dexX7","html_url":"https://github.com/dexX7","followers_url":"https://api.github.com/users/dexX7/followers","following_url":"https://api.github.com/users/dexX7/following{/other_user}","gists_url":"https://api.github.com/users/dexX7/gists{/gist_id}","starred_url":"https://api.github.com/users/dexX7/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dexX7/subscriptions","organizations_url":"https://api.github.com/users/dexX7/orgs","repos_url":"https://api.github.com/users/dexX7/repos","events_url":"https://api.github.com/users/dexX7/events{/privacy}","received_events_url":"https://api.github.com/users/dexX7/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/OmniLayer/omnicore/labels/meta%20dex","name":"meta dex","color":"5319e7"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-04-22T14:14:56Z","updated_at":"2015-05-08T00:47:16Z","closed_at":null,"body":"It is given that certain rational numbers can not be represented as floating point with any finite precision, and it's representation would have an endlessly repeating sequence, resulting in an approximation of the actual value. While this likely only affects the fractional part of numbers, there are other pitfalls, and depending on the level of precision, there are gaps between numbers (for example `9007199254740993` doesn't exist, when using `double`).\r\n\r\nAt this point it is unclear, if the meta DEx might be affected by similar issues, which currently uses [boost::multiprecision::cpp_dec_float_100](http://www.boost.org/doc/libs/1_58_0/libs/multiprecision/doc/html/boost_multiprecision/tut/floats/cpp_dec_float.html) to represent numbers, which are further transformed into strings and cut after a certain number of digits. This primarily affects the calculation of unit prices, and related values, such as the updated amount desired by a seller, the updated amount desired by a buyer, the number of units a buyer receives, and the order matching, which is based on the unit price.\r\n\r\nTo avoid potential pitfalls related to floating-point numbers, suggestions so far were to use [boost::rational](http://www.boost.org/doc/libs/1_58_0/libs/rational/rational.html) to represent rational numbers, or to use [boost::multiprecision::int128_t](http://www.boost.org/doc/libs/1_58_0/libs/multiprecision/doc/html/boost_multiprecision/tut/ints/cpp_int.html) with plain integer math for the core calculations.\r\n\r\nIt should be discussed, whether this is an actual issue, and how it should be addressed."},"comment":{"url":"https://api.github.com/repos/OmniLayer/omnicore/issues/comments/100056546","html_url":"https://github.com/OmniLayer/omnicore/issues/23#issuecomment-100056546","issue_url":"https://api.github.com/repos/OmniLayer/omnicore/issues/23","id":100056546,"user":{"login":"zathras-crypto","id":5633351,"avatar_url":"https://avatars.githubusercontent.com/u/5633351?v=3","gravatar_id":"","url":"https://api.github.com/users/zathras-crypto","html_url":"https://github.com/zathras-crypto","followers_url":"https://api.github.com/users/zathras-crypto/followers","following_url":"https://api.github.com/users/zathras-crypto/following{/other_user}","gists_url":"https://api.github.com/users/zathras-crypto/gists{/gist_id}","starred_url":"https://api.github.com/users/zathras-crypto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zathras-crypto/subscriptions","organizations_url":"https://api.github.com/users/zathras-crypto/orgs","repos_url":"https://api.github.com/users/zathras-crypto/repos","events_url":"https://api.github.com/users/zathras-crypto/events{/privacy}","received_events_url":"https://api.github.com/users/zathras-crypto/received_events","type":"User","site_admin":false},"created_at":"2015-05-08T00:47:16Z","updated_at":"2015-05-08T00:47:16Z","body":"> These offers should match, but currently don't, and the comparison fails here:\r\n\r\nIsn't that because \r\n```if (pnew->inversePrice() < sellers_price) {```\r\ninstead of\r\n```if (pnew->inversePrice() <= sellers_price) {```\r\n?"}}