Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: "Christoph M. Becker" Newsgroups: comp.lang.javascript Subject: IEEE 754 (was: IE and IEE 754) Date: Fri, 29 Aug 2014 23:29:58 +0200 Organization: solani.org Lines: 48 Message-ID: References: <87fvgh1qu9.fsf@bsb.me.uk> <87sikgzz71.fsf@bsb.me.uk> <3souv99slp2vt6nktr48gadd2e4r8th8o4@4ax.com> <871ts0md0v.fsf@bsb.me.uk> <87mwangjzy.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit X-Trace: solani.org 1409347788 21050 eJwVyrEBwDAIA7CXIMHQd0xi/j+h7aZB2Ol5KhIZGEw+V3CFomYbu0YqDlf3/U98YIl0k7nhBTU8Eds= (29 Aug 2014 21:29:48 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Fri, 29 Aug 2014 21:29:48 +0000 (UTC) User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 X-User-ID: eJwNxcEBgDAIA8CVICGUdazA/iPofU5Mz/dEKkOrLVmBQ6LH9053W3sBpD1AvV7/h7PXIoQPEjUQgg== In-Reply-To: <87mwangjzy.fsf@bsb.me.uk> Cancel-Lock: sha1:1vXBvRhpSfnFeXvoX2fO85yVqsY= X-NNTP-Posting-Host: eJwNysERACEIA8CWREkYy+GA9F+Ct+/FobHCCToEMXNotmJNIopn45YA9Z72T5YtzwHq/PXmAyS2EeU= Xref: csiph.com comp.lang.javascript:25783 Ben Bacarisse wrote: > Gene Wirchenko writes: > >> 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... According to John's fine IEEE 754 double format calculator[1] that is correct. The hexadecimal representation is 405edccccccccccd, by the way. >> 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... Correct. Hexadecimal representation: 40c81c7fffffffff > 12345.000000000000000000... Correct. Hexadecimal representation: 40c81c8000000000 > 12345.000000000001818989... Correct. Hexadecimal representation: 40c81c8000000001 > and 12345.0 is the closest. [1] -- Christoph M. Becker