Article View: borland.public.jbuilder.java.language
Article #8540Re: double division rounding error
From: Tor Iver Wilhelmsen
Date: Tue, 13 Mar 2001 08:30
Date: Tue, 13 Mar 2001 08:30
19 lines
1587 bytes
1587 bytes
"Ron Reynolds" <ron@ronreynolds.com> writes: > but my question is why this sort of rounding error pops up with > such low-precision numbers and what's the accepted way of > handling this sort of problem? It's not a rounding problem, but a side-effect of trying to represent decimal numbers as "a * 2^b" - not all decimal numbers fit this rather strict limitation. A common example which illustrates it is trying to fully represent 1/3 as a base 10 decimal. You can start writing 0.3333333333..., but as soon as you get tired and stop, you have introduced a rounding error. Now, if you add a condition where you _have_ to stop because the number of digits is limited, you see that the rounding error inevitably crops up. If precision is important to you, do all computations with scaled ints/longs or java.math.BigDecimal.
Technical Details
Message-ID:
<usnkioyup.fsf@sds.no>Path:
arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!logbridge.uoregon.edu!acadiau.ca!acadiau.ca!hub.org!hub.org!PeerFeed.KWeb.on.ca!bornews.borland.com!not-for-mailReferences:
<3aad499f$1_2@dnews>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,1db527391e14d00c X-Google-Attributes: gidf74b3,public X-Google-ArrivalTime: 2001-03-13 00:36:07 PST Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!logbridge.uoregon.edu!acadiau.ca!acadiau.ca!hub.org!hub.org!PeerFeed.KWeb.on.ca!bornews.borland.com!not-for-mail From: Tor Iver Wilhelmsen <tor.wilhelmsen@sds.no> Newsgroups: borland.public.jbuilder.java.language Subject: Re: double division rounding error Date: 13 Mar 2001 09:30:06 +0100 Organization: Another Netscape Collabra Server User Lines: 19 Sender: towi@SDSA1761 Message-ID: <usnkioyup.fsf@sds.no> References: <3aad499f$1_2@dnews> NNTP-Posting-Host: pc4-252.sds.no X-Newsreader: Gnus v5.5/Emacs 20.3