Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!news-out.readnews.com!transit3.readnews.com!news-out.news.tds.net!newsreading01.news.tds.net!53ab2750!not-for-mail From: "Patricia Shanahan" Subject: Re: What is the command to do a power of a value Message-ID: <50181D61.55738.calajapr@time.synchro.net> X-Comment-To: Andreas Leitgeb Newsgroups: comp.lang.java.programmer In-Reply-To: <50181D61.55736.calajapr@time.synchro.net> References: <50181D61.55736.calajapr@time.synchro.net> X-FTN-AREA: COMP.LANG.JAVA.PROGRAMMER X-FTN-MSGID: 1:261/38 0a3527a5 X-FTN-REPLY: 1:261/38 c86ecd96 Content-Type: text/plain; charset=IBM437 Content-Transfer-Encoding: 8bit X-Gateway: time.synchro.net [Synchronet 3.16a-Win32 NewsLink 1.98] Lines: 50 Date: Tue, 31 Jul 2012 18:02:33 GMT NNTP-Posting-Host: 69.21.70.65 X-Complaints-To: news@tds.net X-Trace: newsreading01.news.tds.net 1343757753 69.21.70.65 (Tue, 31 Jul 2012 13:02:33 CDT) NNTP-Posting-Date: Tue, 31 Jul 2012 13:02:33 CDT Organization: tds.net Xref: csiph.com comp.lang.java.programmer:16770 To: Andreas Leitgeb From: "Patricia Shanahan" To: Andreas Leitgeb From: Patricia Shanahan On 7/30/2012 6:22 AM, Andreas Leitgeb wrote: > On Sun, 29 Jul 2012 21:28:11 -0700 (PDT), xvictoryeohx@gmail.com wrote: >> C=L(1+i/100)power of n > > x ^ n = exp ( log(x) * n ) | x = (1 + i/100) > = exp ( log( 1 + i/100 ) * n) > = exp ( log1p ( i/100 ) * n) > > If you're doing more calculations with same interest-rate but > different periods, then you may want to calculate > double logBase = Math.log1p( i / 100 ); > once, and use that for the individual calculations: > C = L * Math.exp( logBase * n ) > > The gist of this response is, that for the kind of base (1+i/100), > you better separate the pow operation out into log and exp, and > actually use log1p on (i/100) instead of log on (1+i/100) for > efficiency's and precision's sake. > > For "Math.log1p" see: > http://docs.oracle.com/javase/6/docs/api/java/lang/Math.html#log1p%28double%2 9 > I am curious about why you expect this to be more precise than: "The computed result must be within 1 ulp of the exact result. Results must be semi-monotonic." (From the pow description). Or do you know of cases where Math.pow gets an over-large rounding error? Note that I am not disagreeing with your method for calculating a power of a number slightly greater than 1, just questioning whether doing it explicitly gets more precise answers than using Math.pow. Patricia -+- BBBS/Li6 v4.10 Dada-1 + Origin: Prism bbs (1:261/38) -+- Synchronet 3.16a-Win32 NewsLink 1.98 Time Warp of the Future BBS - telnet://time.synchro.net:24 --- BBBS/Li6 v4.10 Dada-1 * Origin: Prism bbs (1:261/38) --- Synchronet 3.16a-Win32 NewsLink 1.98 Time Warp of the Future BBS - telnet://time.synchro.net:24