Path: csiph.com!aioe.org!.POSTED!not-for-mail From: =?UTF-8?Q?Arne_Vajh=c3=b8j?= Newsgroups: comp.lang.java.programmer Subject: Re: [OT] Re: missing import java.lang.Comparable Date: Fri, 8 Jul 2016 20:18:19 -0400 Organization: Aioe.org NNTP Server Lines: 33 Message-ID: References: <00835840-56aa-4ba2-b496-e364a62a38e8@googlegroups.com> <8668311a-503f-46b6-909c-dcbfbfc5ce19@googlegroups.com> <128e7e20-d311-413d-abbc-e885b34ae402@googlegroups.com> <87dc5bee-f689-4f2e-90a8-a43a2de9fe49@googlegroups.com> <638a1d64-f125-4456-a20b-4dbf45f49da2@googlegroups.com> NNTP-Posting-Host: 7SK6yTFfqwlIPNBLl3l7Qg.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.1.1 X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.lang.java.programmer:34814 On 7/8/2016 10:35 AM, Eric Douglas wrote: > On Friday, July 8, 2016 at 10:16:23 AM UTC-4, Eric Sosman wrote: >> No one would want that. Also, no one experiences that (not in >> Java, at any rate). I get your point, though, that floating-point >> arithmetic can be surprising. > > I don't know if or how it happens with whole numbers offhand but it's > definitely an issue with decimals, and that is more than financials. > When you're trying to write an application that manages inventory > quantities and calculates the decimals as in to represent the > percentage of a can of paint, then this is a problem. Program: double > a = .0002; double b = .0001; System.out.println(a + b); Result: > 3.0000000000000003E-4 But that result is really correct. .0002 +/- some uncertainty + .0001 +/- some uncertainty is 3.0000000000000003E-4 +/- some uncertainty But maybe your inventory system do not work with built in uncertainty. Point being that in this case you should not use floating point either. Every time you think about using float and double to store some data always ask whether values has uncertainty. If not drop float/double and start looking at something else (maybe BigDecimal). Arne