Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.datemas.de!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: Wed, 27 Aug 2014 22:35:04 +0200 Organization: solani.org Lines: 43 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 8bit X-Trace: solani.org 1409171697 30236 eJwFwQkBwDAIA0BL40kGcigU/xJ6B6OwfyfoWKzCq7mz8vmkeVd0lyHPXRSoIhNjoXmnTtgDKQARkA== (27 Aug 2014 20:34:57 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Wed, 27 Aug 2014 20:34:57 +0000 (UTC) User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 X-User-ID: eJwFwYEBwCAIA7CXcNAyz0Gw/59gAudiZxAMCIo7q0yUy69+N/fapcAU28ANHTWaR/nl1AMuuBH1 In-Reply-To: Cancel-Lock: sha1:KCO3pu8A4q+PJCz4fTaqH/EzdFw= X-NNTP-Posting-Host: eJwFwYEBwCAIA7CXRGir5wyB/09YAqfxKQgGBuPaMmNnZ75zOcduuKVXw1H15mPF2hIa0PoBGUQQ2g== Xref: csiph.com comp.lang.javascript:25744 Evertjan. wrote: > RobG wrote on 27 aug 2014 in comp.lang.javascript: > >> In most browsers: >> 0.57 + 8.36 + 3.36 + 0.19 = 12.479999999999999 >> in IE it returns: >> 12.479999999999998 >> Is IE wrong, or is the above difference allowable within IEEE 754? > > Both are and must be wrong in the sense that the binary converions > of floting point fractional decimal values NEVER can be right. Wrong. Consider e.g. 0 or 2. > So why use a standard that defines how wrong they must be? To be able to quantify the inaccuracy. > Just remember every time, > that you should not compare such values without prior rounding. AFAIK it is common to compare for equality with Math.abs(a - b) < epsilon See also Number.EPSILON[1]. > If you are a sticker for correctness and these are monitary values, > like $ or €, use integer cent values in variables, and write decimals with > string manupulation. Are you suggesting that storing $123.45 as 12345 is better than storing it as 123.45? As ECMAScript implementations typically have no integer type, there is no difference regarding the precision of further calculations. [1] -- Christoph M. Becker