Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!news2.arglkargh.de!news.mixmin.net!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: "Christoph M. Becker" Newsgroups: comp.lang.javascript Subject: Re: IE and IEE 754 Date: Thu, 28 Aug 2014 22:15:21 +0200 Organization: solani.org Lines: 43 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: solani.org 1409256914 16376 eJwFwQkBwDAIA0BLfAlFDlvBv4Tewan8MwgGFqsW1LnbTPVCpGDHtGJrMd0ztyU+9sg5MH8T3xED (28 Aug 2014 20:15:14 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Thu, 28 Aug 2014 20:15:14 +0000 (UTC) User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 X-User-ID: eJwFwYEBwCAIA7CXQFuUc1iF/09Ywh0eOggGOJzaOh1c6EeYs+rm6NUne3k5y2FdQieFKP4n7xGL In-Reply-To: Cancel-Lock: sha1:S43Xx9DoIb6qnGlsNiIa4itW/8Q= X-NNTP-Posting-Host: eJwNwokVADEEBcCWrI9QjiP6LyH7ZhT2WR8xNdH9yVXmuEWTlKs1hMI6wWNHyz0C3YYjM5zzACDAEWY= Xref: csiph.com comp.lang.javascript:25763 Gene Wirchenko wrote: > On Thu, 28 Aug 2014 00:47:16 +0200, "Christoph M. Becker" > wrote: > >> Evertjan. wrote: >> >>> Compare this to: >>> >>> document.write(23.45-23.4); // 0.05000000000000071 >>> >>> You are quite in your right >>> not to call the first method "better", >>> but in monetary calculus, I would disagree. >> >> Well, then try to calculate the German VAT with "integers": >> >> 2345 * 1.19 -> 2790.5499999999997 > ^^^^ > This is not an integer. No, of course not. I just wanted to show that storing dollars as cents doesn't solve all problems regarding monetary calculations. Of course, one could use the following instead: 2345 * 119 / 100 But you may see the potential problems with this approach. >> Anyway, you can't do arbitrary monetary calculations reliably with IEEE >> 754 doubles. However, that is the only number type that is guaranteed >> to be supported by conforming ECMAScript implementations. > > Not arbitrary ones, but if you stick with integers of up to 15 > digits, it can work just fine. If one cares about all the gory details and avoids the pitfalls. IMHO one is better off to use a bigint library when there is really the need for exact integer calculations. -- Christoph M. Becker