Path: csiph.com!news.swapon.de!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Eric Sosman Newsgroups: comp.lang.java.programmer Subject: Re: [OT] Re: missing import java.lang.Comparable Date: Mon, 11 Jul 2016 17:21:50 -0400 Organization: A noiseless patient Spider Lines: 49 Message-ID: References: <128e7e20-d311-413d-abbc-e885b34ae402@googlegroups.com> <87dc5bee-f689-4f2e-90a8-a43a2de9fe49@googlegroups.com> <638a1d64-f125-4456-a20b-4dbf45f49da2@googlegroups.com> <60a5ccde-2657-48d6-b3dd-04ec1a0973ab@googlegroups.com> <6f69c451-849d-4672-9025-7880a62bd72d@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Mon, 11 Jul 2016 21:21:53 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="2d081e2f7155c28005d4472f67c2f43d"; logging-data="2488"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18n34wBRYJ3UQg8K8lNbyb/" User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 In-Reply-To: Cancel-Lock: sha1:jLWsNMezqomOP0T4aagyxnmRVZ0= Xref: csiph.com comp.lang.java.programmer:34864 On 7/11/2016 4:44 PM, Eric Douglas wrote: > On Monday, July 11, 2016 at 3:09:42 PM UTC-4, Eric Sosman wrote: >> Question: What should that monthly rate be? To put it another >> way, what is the rate R such that (1+R/100)**12 = 1.011 = 1 + 1.1%? >> Calculate in any integer base you prefer, but answer exactly. >> >> (This sort of problem also makes a good rejoinder to people who >> maintain that *all* financial calculations should use integer math.) > > I will read that article Lew linked and see if it helps. This is tricky to understand because it's basic math, we're adding 2 numbers not dividing. I have a college degree in computer business, not computer science. I've taken algebra, geometry, statistics. I have not taken trigonometry or calculus or learned anything I can recall about imaginary numbers. 1 + 2 = 3, and .0001 + .0002 = .0003. Most people would agree. > > Financial math involves division where imprecise numbers are involved and typically that means rounding. Someone making $50,000 per year paid weekly, calculated on a 52 week year makes a gross $961.5384615384615 per week, so it's rounded to $961.53 and some weeks $961.54 to make up the difference. I don't know how banks work with interest but I would think they have to be the same. If you want exactly 1.1% annual interest but you calculate it monthly you have a number you have to round and you alternate rounding it up and down until the result comes out even. > 1.1 / 12 = 0.091666666... > $50,000 + 1.1% = $50,550 > $50,000 * 0.000916666 = $45.8333 > ($45.83 * 8) + ($45.84 * 4) = $550 It may be little more than a distraction, but that's *simple* interest. Compound interest (where each period pays interest on the entire balance, including the previous periods' interest) is a different beast altogether. (And the reason neither decimal nor binary nor any other integer base will work is that the twelfth root of 1.011 ~= 1.000912+ is an "irrational number," a value that cannot be represented as a fraction M/N for *any* integers M,N.) If you're going to write computer programs, I strongly suggest you get a little better understanding of how computers represent and calculate with numbers. It is a mistake to believe that every digit of every floating-point result is "significant," but it is also a mistake to think that they're all meaningless. A full-scale course in Numerical Analysis may not be necessary (depending on where your interests lie), but a study of the first one or two chapters of a NA introductory text might be a good idea. It'll make you better informed as to what you can and cannot expect from a calculation. > Computers aren't made to compute fractions but that's the part I struggle with is what do fractions have to do with basic addition. Well, your difficulty concerned adding fractions. You complained that 0.0001 + 0.0002 should equal 0.0003 but the computer gives a different sum. What you *ought* to understand is that none of these three fractions is represented without error; you're really adding (0.0001 + x) + (0.0002 + y) = (0.0003 + z) ... for very small but non-zero x,y,z. -- esosman@comcast-dot-net.invalid "Don't be afraid of work. Make work afraid of you." -- TLM