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: Thu, 28 Aug 2014 02:55:40 +0200 Organization: solani.org Lines: 30 Message-ID: References: <87fvgh1qu9.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit X-Trace: solani.org 1409187333 20484 eJwNwYkRwDAIA7CVwmNzGQco7D9CKsEo7HCCjsUGb2tmic53OL5+eAeRyrGGjRd89VddKvEAHUoQ8g== (28 Aug 2014 00:55:33 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Thu, 28 Aug 2014 00:55:33 +0000 (UTC) User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 X-User-ID: eJwFwQcBwEAIBDBLUNYh51n+JTQxcfYOdXO1swvu25KOqYWQcEwneJ/CBNuBKSR5ptP3Vn8ofxEY In-Reply-To: <87fvgh1qu9.fsf@bsb.me.uk> Cancel-Lock: sha1:wcfRG7yDfRAgEw41iJHr7rpBEpI= X-NNTP-Posting-Host: eJwFwYEBwCAIA7CXxELLzmGg/59gEqCx5Qx63LjCzVXJY8qtz1tps1DtZ5Cz429aGZTlsPEHCrYQcw== Xref: csiph.com comp.lang.javascript:25750 Ben Bacarisse wrote: > "Christoph M. Becker" writes: > >> Evertjan. wrote: > >>> If you are a sticker for correctness and these are monitary values, >>> like $ or [euro-sign], 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. > > 12345 can be represented exactly in binary floating point (given enough > bits, and we certainly have that) whereas 123.45 can't be. Thanks for pointing this out. :) After quite some reconsideration I have to admit that I was wrong. Of course, 123.45 can't be represented exactly as *binary* floating point number, while 12345 can be. However, it seems to me that multiplying 123.45 (0x405edccccccccccd) with 100 doesn't solve the issue, i.e. the result is not necessarily equal to 12345 (0x40c81c8000000000). -- Christoph M. Becker