Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Martin Gregorie Newsgroups: comp.lang.java.programmer Subject: Re: [OT] Re: missing import java.lang.Comparable Date: Wed, 20 Jul 2016 21:28:45 -0000 (UTC) Organization: A noiseless patient Spider Lines: 43 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Date: Wed, 20 Jul 2016 21:28:45 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="e5160e2be48f1ea550cf61512446f525"; logging-data="11955"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19uiQMBG1Pfw73OVIb0uutvsPjErP0O57U=" User-Agent: Pan/0.140 (Chocolate Salty Balls; GIT 3663720 git://git.gnome.org/pan2) Cancel-Lock: sha1:S7Y3cdJeHqDf+oOB3BihBgiIsDE= Xref: csiph.com comp.lang.java.programmer:35024 On Wed, 20 Jul 2016 12:01:33 -0700, Gene Wirchenko wrote: > On Tue, 19 Jul 2016 21:54:43 -0000 (UTC), Martin Gregorie > wrote: > >>On Tue, 19 Jul 2016 16:37:28 -0400, Jerry Stuckle wrote: > > [snip] > >>> And you still haven't described how Java (not javascript) handles >>> decimal numbers with at least 18 digits of accuracy. >>> >>I don't think it can: he's already said that Javascript's only internal >>numeric representation is a 64 bit floating point number, i.e. a double, >>which we already know can not support 18 significant digits since its >>only got 53 bits for the mantissa, i.e. just under 15 significant >>digits. > > Just under *16* digits. (log10 2 ~= .30103 times 53 bits gives > ~15.95 decimal digits. So 15 usable. > the 53 bits includes the sign, so the magnitude is 2^52, which is 4.5^15 so only 14 usable digits. In this Java and javascript are identical. > Actually, Mr. Gregorie, the innumerate one would be you in this > case. I know how floating-point works internally so I know that what I > am doing is safe (within limits). > Not really - you're disregarding the effect of inexact representation. It may be OK with relatively few arithmetic operations in small values, but the errors can accumulate rather fast if the number of operations on each value grows (and especially if currency conversions or interest is involved) and a lot of the values are aggregated. I'll stick to using Java longs, BigDecimal and COBOL (if I must) for anything more complex than personal accounting systems, thanks. -- martin@ | Martin Gregorie gregorie. | Essex, UK org |