Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.swapon.de!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Ben Bacarisse Newsgroups: comp.lang.javascript Subject: Re: IE and IEE 754 Date: Thu, 28 Aug 2014 11:27:30 +0100 Organization: A noiseless patient Spider Lines: 35 Message-ID: <87sikgzz71.fsf@bsb.me.uk> References: <87fvgh1qu9.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx05.eternal-september.org; posting-host="017616aa25f81ec581c44d76d61ba2f3"; logging-data="3656"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+N29qTTJZomN5MEf9R4bXEJUP1Cw7m5fA=" Cancel-Lock: sha1:H4RJuiehKwChU6FFhBbC6eswz4s= sha1:I4Zi0r9GX+j1IHG6qnInIRI6XM4= X-BSB-Auth: 1.757693a6a2097b4ead5d.20140828112730BST.87sikgzz71.fsf@bsb.me.uk Xref: csiph.com comp.lang.javascript:25756 "Christoph M. Becker" writes: > 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). I think it must. The ECMAScript specification imports IEEE 754's strict rounding and representation rules. The IEEE FP value closest to 123.45, when multiplies by 100 must yield 12345 according to those rules. -- Ben.