Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!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: Fri, 29 Aug 2014 20:42:57 +0100 Organization: A noiseless patient Spider Lines: 58 Message-ID: <87mwangjzy.fsf@bsb.me.uk> References: <87fvgh1qu9.fsf@bsb.me.uk> <87sikgzz71.fsf@bsb.me.uk> <3souv99slp2vt6nktr48gadd2e4r8th8o4@4ax.com> <871ts0md0v.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx05.eternal-september.org; posting-host="017616aa25f81ec581c44d76d61ba2f3"; logging-data="7640"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/XqvxsLIPDzysYwInfuKs4nPaYAYamVeU=" Cancel-Lock: sha1:julJ7h/UspzzxMvo8sqfQwzQQC4= sha1:Kd7WH6Ghsg+t/tQu5DHhqXqT6Lk= X-BSB-Auth: 1.ced320cd41fa07e3e376.20140829204257BST.87mwangjzy.fsf@bsb.me.uk Xref: csiph.com comp.lang.javascript:25782 Gene Wirchenko writes: > On Fri, 29 Aug 2014 00:04:48 +0100, Ben Bacarisse > wrote: > >>Gene Wirchenko writes: >> >>> On Thu, 28 Aug 2014 11:27:30 +0100, Ben Bacarisse >>> wrote: >>> >>> [snip] >>> >>>>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. >>> >>> Why? What if the value that you have (and want) happens to be >>> the value closest to 123.45? When you multiply that value by 100, >>> wouldn't you want 100 times the value instead of 12345? >> >>Yes, but you won't get it. You'll get the nearest floating point >>number, which is 12345. Am I missing your point? > > Yes. The value closest to 123.45 can be represented exactly. Sure. To be specific, for IEEE 754 double, it's 7B.733333333334 in hex. Using enough decimal digits to see what happening, that's about 123.45000000000000284217... > So can 100 times that value. That's an odd idea. Why do you think it might be? > That value is not 12345. Yup, it's 12345.000000000000284217... > That 100 times value would be what is wanted, not 12345. It's what you want, but, as I said, what you'll get is the nearest representable floating point number. The three candidates are centred on 12345: 12344.999999999998181011... 12345.000000000000000000... 12345.000000000001818989... and 12345.0 is the closest. (Assuming I have not made some blunder with the arithmetic -- please check it.) I'm still not sure I've got your point, but you've said what appears to be the same thing twice now, so I don't know what else to say. -- Ben.