<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Regarding Decimal - it's not yet implemented on Linux, but it's a work in progress.<div class=""><br class=""></div><div class="">Alex<br class=""><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 12 Sep 2016, at 18:49, Stephen Canon via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Sep 12, 2016, at 1:26 PM, Jens Alfke via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:</div><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Sep 12, 2016, at 10:10 AM, Teej . via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="font-family: Alegreya-Regular; font-size: 15px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><span class="Apple-tab-span" style="white-space: pre;">        </span>…in spite of the CPU’s quirks in handling floating point numbers in a maddening inaccurate manner.</div></div></blockquote><div class=""><br class=""></div><div class="">Well, in the CPU’s defense, it’s only inaccurate because the puny humans insist on dividing their currency into fractions of 1/10, which has no exact representation in binary. (Apparently this is an ancient tradition commemorating the number of bony outgrowths on certain extremities of their grotesque meat-bodies.) I could — I mean, <i class="">the computers </i>could — point out that if we divided our currency units into 7 pieces, our precious decimal numbers would quickly become inaccurate too. :)</div></div></div></div></blockquote><br class=""></div><div class="">Expanding a bit on what Jens wrote here: <b class="">decimal (unlike friendship) is not magic</b>. All computer models of real-number arithmetic are necessarily inexact, because (almost all) real numbers are not computable. There are a bunch of reasonable choices that one can make, however (this is not an exhaustive list, just a sampling of the design space):</div><div class=""><br class=""></div><div class=""><b class="">Binary floating point</b></div><div class="">Pro: represents modest integers exactly, extremely fast hardware implementations, fixed memory size, and rounding errors are extremely uniform—they don’t vary much with the number being represented.</div><div class="">Con: almost no decimal fractions have exact representations.</div><div class=""><br class=""></div><div class=""><b class="">Decimal floating point</b></div><div class="">Pro: represents modest integers and decimal fractions exactly, slower than binary but still faster than almost anything else, fixed memory size.</div><div class="">Con: at least an order of magnitude slower than binary floating-point, and rounding error is significantly less scale-invariant.</div><div class=""><br class=""></div><div class=""><b class="">Fixed-size rationals</b></div><div class="">Pro: represents all modestly-sized integers and fractions exactly, fixed memory size, four basic operations are exact until you hit the limits of representation.</div><div class="">Con: denominators quickly grow too quickly to be used for non-trivial computations (this is usually a deal-breaker).</div><div class=""><br class=""></div><div class=""><b class="">Arbitrary-precision rationals</b></div><div class="">Pro: closed under four basic operations, represents most numbers most people will use exactly.</div><div class="">Con: representations get extremely large extremely quickly, large memory footprint if you have more than a few numbers.</div><div class=""><br class=""></div><div class=""><b class="">Computable real numbers</b></div><div class="">Pro: any number you can describe, you can work with.</div><div class="">Con: your numbers are now computer programs, and you arithmetic system is Turing-complete. Testing for equality is equivalent to solving the halting problem.</div><div class=""><br class=""></div><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><div class=""><blockquote type="cite" class="">Teej . via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:</blockquote><blockquote type="cite" class=""><br class=""></blockquote></div></div></div></div><div class=""><blockquote type="cite" class="">It still does not answer my question on why we can’t just provide a decimal data type.</blockquote><br class=""></div><div class="">The only problem here is the “just”. We can and will provide a decimal data type. Like many other language changes, that we can and will do, it requires engineering time, and there are finite engineering resources available to work on it.</div><div class=""><br class=""></div><div class="">Keep in mind that decimal will not magically solve all accuracy problems, however. 1/3 is just as inaccurate in decimal as it is in binary floating-point (actually, it’s less accurate in decimal than in a comparable binary format due to the aforementioned non-uniformity of decimal rounding error).</div><div class=""><br class=""></div><div class="">– Steve</div></div>_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-users<br class=""></div></blockquote></div><br class=""></div></div></body></html>