{"action":"created","issue":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/11081","labels_url":"https://api.github.com/repos/JuliaLang/julia/issues/11081/labels{/name}","comments_url":"https://api.github.com/repos/JuliaLang/julia/issues/11081/comments","events_url":"https://api.github.com/repos/JuliaLang/julia/issues/11081/events","html_url":"https://github.com/JuliaLang/julia/issues/11081","id":72447517,"number":11081,"title":"improve documentation of numeric literals","user":{"login":"ScottPJones","id":11798751,"avatar_url":"https://avatars.githubusercontent.com/u/11798751?v=3","gravatar_id":"","url":"https://api.github.com/users/ScottPJones","html_url":"https://github.com/ScottPJones","followers_url":"https://api.github.com/users/ScottPJones/followers","following_url":"https://api.github.com/users/ScottPJones/following{/other_user}","gists_url":"https://api.github.com/users/ScottPJones/gists{/gist_id}","starred_url":"https://api.github.com/users/ScottPJones/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ScottPJones/subscriptions","organizations_url":"https://api.github.com/users/ScottPJones/orgs","repos_url":"https://api.github.com/users/ScottPJones/repos","events_url":"https://api.github.com/users/ScottPJones/events{/privacy}","received_events_url":"https://api.github.com/users/ScottPJones/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/JuliaLang/julia/labels/doc","name":"doc","color":"02d7e1"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":38,"created_at":"2015-05-01T14:51:38Z","updated_at":"2015-05-03T22:28:07Z","closed_at":"2015-05-01T20:52:30Z","body":"In #8964, I was pointing out some serious inconsistencies that occur with the default or built-in numeric types in Julia, and how numeric constants are not handled consistently.\r\nA decimal integer literal will start off as Int64 (or I imagine Int32 on 32-bit machines?), then go to Int128, and finally to Base.GMP.BigInt, depending on the value, not it's length (0, 00, 00000000...)\r\nare all Int64, no matter how many leading 0s there are.\r\nA hexadecimal literal, on the other hand, starts off as an unsigned integer, but it is the *length*, not the actual value, that determines it's type... i.e. 0x0 and 0x00 are both UInt8s, but 0x000 and 0x0000 are UInt16, and 0x00000 - 0x00000000 are UInt32... and so forth, up through UInt64, UInt128, and then, magically, it changes from an unsigned type, to a Base.GMP.BigInt...\r\nThis is very apparent if you use the ~ operator on the literal... a frequent thing to do with a mask value.\r\nFloats are even worse - they are *always* Float64, even if Float64 is not large enough to represent the value (forgetting for the moment that binary floating point is not suitable for exactly representing base-10 literals...]."},"comment":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/comments/98551106","html_url":"https://github.com/JuliaLang/julia/issues/11081#issuecomment-98551106","issue_url":"https://api.github.com/repos/JuliaLang/julia/issues/11081","id":98551106,"user":{"login":"ScottPJones","id":11798751,"avatar_url":"https://avatars.githubusercontent.com/u/11798751?v=3","gravatar_id":"","url":"https://api.github.com/users/ScottPJones","html_url":"https://github.com/ScottPJones","followers_url":"https://api.github.com/users/ScottPJones/followers","following_url":"https://api.github.com/users/ScottPJones/following{/other_user}","gists_url":"https://api.github.com/users/ScottPJones/gists{/gist_id}","starred_url":"https://api.github.com/users/ScottPJones/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ScottPJones/subscriptions","organizations_url":"https://api.github.com/users/ScottPJones/orgs","repos_url":"https://api.github.com/users/ScottPJones/repos","events_url":"https://api.github.com/users/ScottPJones/events{/privacy}","received_events_url":"https://api.github.com/users/ScottPJones/received_events","type":"User","site_admin":false},"created_at":"2015-05-03T22:28:07Z","updated_at":"2015-05-03T22:28:07Z","body":"@jiahao Sorry, but your examples aren't the example Mike Cowlishaw was talking about, and the default in julia has the problem...\r\n```julia\r\njulia> round(.7*.05*100)\r\n3.0\r\n```\r\nDecimal floating point would give the expected answer (the one the government will insist you pay, i.e.\r\n4 cents, not 3...\r\nI would say that the example *VERY* clearly shows the danger of using binary floating point for data like currency (which is why databases all have decimal number support, and binary floating point was generally added much later...)\r\n\r\nAlso, I didn't say that *nobody* used different rounding modes for *binary* floating point... as I said, until the mid 1980's, binary floating point was a mess, and for some years afterwards, because there were still a lot of platforms that used their own proprietary software libraries or hardware...\r\nI was talking about *facts*, which you could check, about the standards available in computer languages prior to 1985 with the advent of IEEE standard... and even the IEEE standard apparently recommends rounding in the way I have stated all along!\r\n\r\n>Until the 1980s, the rounding method used in floating-point computer arithmetic was usually fixed by the hardware, poorly documented, inconsistent, and different for each brand and model of computer. This situation changed after the IEEE 754 floating point standard was adopted by most computer manufacturers. The standard allows the user to choose among several rounding modes, and in each case specifies precisely how the results should be rounded. These features made numerical computations more predictable and machine-independent, and made possible the efficient and consistent implementation of interval arithmetic.\r\n\r\nLooking at the rounding names in your example, I see that what I had always heard called \"rounding up\", is called RoundNearest, which is also the default in Julia (on the Internet, I saw that what I'm used to is also called \"rounding half up\"...).  It is also called \"banker's rounding\"... I've even heard that that method was found used on tables dating back to the time of the Summerians, with a base 60 system...\r\nThe \"statistician's rounding\" is comparatively recent, and is not the norm for computer languages\r\n(even in Julia, you'd have to select it...).\r\n\r\nI never saw any other rounding mode than 5-9 rounding up in the ANSI standard languages of the time, or the calculators of the time either (which were all decimal arithmetic either).\r\nPlease, if you have a reference that shows otherwise, please show it!\r\n\r\nHere is another example: from Julia:\r\n```julia\r\njulia> x = BigFloat(1.05)\r\n1.0500000000000000444089209850062616169452667236328125e+00 with 256 bits of precision\r\njulia> x * .7 *100\r\n7.349999999999999844568776552478064619168935941990020956785867930344258169839122e+01 with 256 bits of precision\r\njulia> round(x * .7 * 100)\r\n7.3e+01 with 256 bits of precision\r\n```\r\nI see the exact same error here, that was shown on Cowlishaw's presentation.\r\nI also am very surprised that you seem to doubt his presentation... he was a major contributor to the IEEE 754 standard... I'd say he is probably the best known person in the world on the subject!\r\n\r\nBTW, I am *still* curious what system those healthcare teams you are working with use?   Is that a secret, or do you not know?\r\n\r\n"}}