Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #16681
| Date | 2012-07-30 13:15 -0700 |
|---|---|
| From | Patricia Shanahan <pats@acm.org> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: What is the command to do a power of a value |
| References | <5016CF47.55648.calajapr@time.synchro.net> <5016CF47.55649.calajapr@time.synchro.net> |
| Message-ID | <MJCdnYgBj8TFdovNnZ2dnUVZ_jCdnZ2d@earthlink.com> (permalink) |
On 7/30/2012 12:00 PM, Patricia Shanahan wrote: > To: Andreas Leitgeb > From: Patricia Shanahan <pats@acm.org> > > 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. I've thought about this some more, and I think I get it now. If i is reasonably small compared to 100, the 1 + i/100 addition loses several bits of precision. Patricia
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
What is the command to do a power of a value "xvictoryeohx" <xvictoryeohx@1:261/38.remove-rf4-this> - 2012-07-30 19:00 +0000
Re: What is the command to do a power of a value "bugbear" <bugbear@1:261/38.remove-rf4-this> - 2012-07-30 19:00 +0000
Re: What is the command to do a power of a value "glen herrmannsfeldt" <glen.herrmannsfeldt@1:261/38.remove-rf4-this> - 2012-07-30 19:00 +0000
Re: What is the command to do a power of a value "xvictoryeohx" <xvictoryeohx@1:261/38.remove-rf4-this> - 2012-07-30 19:00 +0000
Re: What is the command to do a power of a value "Roedy Green" <roedy.green@1:261/38.remove-rf4-this> - 2012-07-30 19:00 +0000
Re: What is the command to do a power of a value "Andreas Leitgeb" <andreas.leitgeb@1:261/38.remove-rf4-this> - 2012-07-30 19:00 +0000
Re: What is the command to do a power of a value "Patricia Shanahan" <patricia.shanahan@1:261/38.remove-rf4-this> - 2012-07-30 19:00 +0000
Re: What is the command to do a power of a value Patricia Shanahan <pats@acm.org> - 2012-07-30 13:15 -0700
Re: What is the command to do a power of a value glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2012-07-30 22:26 +0000
Re: What is the command to do a power of a value Patricia Shanahan <pats@acm.org> - 2012-07-30 16:01 -0700
Re: What is the command to do a power of a value Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2012-07-30 23:11 +0000
Re: What is the command to do a power of a value "Andreas Leitgeb" <andreas.leitgeb@1:261/38.remove-dpk-this> - 2012-07-31 18:02 +0000
csiph-web