Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #16850 > unrolled thread
| Started by | "xvictoryeohx" <xvictoryeohx@1:261/38.remove-x1c-this> |
|---|---|
| First post | 2012-07-31 20:06 +0000 |
| Last post | 2012-07-31 20:07 +0000 |
| Articles | 11 — 6 participants |
Back to article view | Back to comp.lang.java.programmer
What is the command to do a power of a value "xvictoryeohx" <xvictoryeohx@1:261/38.remove-x1c-this> - 2012-07-31 20:06 +0000
Re: What is the command to do a power of a value "bugbear" <bugbear@1:261/38.remove-x1c-this> - 2012-07-31 20:07 +0000
Re: What is the command to do a power of a value "glen herrmannsfeldt" <glen.herrmannsfeldt@1:261/38.remove-x1c-this> - 2012-07-31 20:07 +0000
Re: What is the command to do a power of a value "xvictoryeohx" <xvictoryeohx@1:261/38.remove-x1c-this> - 2012-07-31 20:07 +0000
Re: What is the command to do a power of a value "Roedy Green" <roedy.green@1:261/38.remove-x1c-this> - 2012-07-31 20:07 +0000
Re: What is the command to do a power of a value "Andreas Leitgeb" <andreas.leitgeb@1:261/38.remove-x1c-this> - 2012-07-31 20:07 +0000
Re: What is the command to do a power of a value "Patricia Shanahan" <patricia.shanahan@1:261/38.remove-x1c-this> - 2012-07-31 20:07 +0000
Re: What is the command to do a power of a value "Patricia Shanahan" <patricia.shanahan@1:261/38.remove-x1c-this> - 2012-07-31 20:07 +0000
Re: What is the command to do a power of a value "glen herrmannsfeldt" <glen.herrmannsfeldt@1:261/38.remove-x1c-this> - 2012-07-31 20:07 +0000
Re: What is the command to do a power of a value "Patricia Shanahan" <patricia.shanahan@1:261/38.remove-x1c-this> - 2012-07-31 20:07 +0000
Re: What is the command to do a power of a value "Andreas Leitgeb" <andreas.leitgeb@1:261/38.remove-x1c-this> - 2012-07-31 20:07 +0000
| From | "xvictoryeohx" <xvictoryeohx@1:261/38.remove-x1c-this> |
|---|---|
| Date | 2012-07-31 20:06 +0000 |
| Subject | What is the command to do a power of a value |
| Message-ID | <50182C7C.55818.calajapr@time.synchro.net> |
From: "xvictoryeohx" <xvictoryeohx@1:261/38.remove-dpk-this> From: "xvictoryeohx" <xvictoryeohx@1:261/38.remove-rf4-this> From: xvictoryeohx@gmail.com C=L(1+i/100)power of n i am stuck here for example square root is Math.sqrt(x) How do i do Power of a value? -+- 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 --- 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
[toc] | [next] | [standalone]
| From | "bugbear" <bugbear@1:261/38.remove-x1c-this> |
|---|---|
| Date | 2012-07-31 20:07 +0000 |
| Message-ID | <50182C7C.55819.calajapr@time.synchro.net> |
| In reply to | #16850 |
To: xvictoryeohx From: "bugbear" <bugbear@1:261/38.remove-dpk-this> To: xvictoryeohx From: "bugbear" <bugbear@1:261/38.remove-rf4-this> To: xvictoryeohx From: bugbear <bugbear@trim_papermule.co.uk_trim> xvictoryeohx@gmail.com wrote: > C=L(1+i/100)power of n > > i am stuck here > for example square root is Math.sqrt(x) > How do i do Power of a value? I have a dim memory from Numerical Analysis that the "obvious" way to evaluate that is inaccurate for small "i" and large "n". BugBear -+- 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 --- 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
[toc] | [prev] | [next] | [standalone]
| From | "glen herrmannsfeldt" <glen.herrmannsfeldt@1:261/38.remove-x1c-this> |
|---|---|
| Date | 2012-07-31 20:07 +0000 |
| Message-ID | <50182C7D.55820.calajapr@time.synchro.net> |
| In reply to | #16850 |
To: xvictoryeohx From: "glen herrmannsfeldt" <glen.herrmannsfeldt@1:261/38.remove-dpk-this> To: xvictoryeohx From: "glen herrmannsfeldt" <glen.herrmannsfeldt@1:261/38.remove-rf4-this> To: xvictoryeohx From: glen herrmannsfeldt <gah@ugcs.caltech.edu> xvictoryeohx@gmail.com wrote: > C=L(1+i/100)power of n > i am stuck here > for example square root is Math.sqrt(x) > How do i do Power of a value? Math.pow(). -- glen -+- 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 --- 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
[toc] | [prev] | [next] | [standalone]
| From | "xvictoryeohx" <xvictoryeohx@1:261/38.remove-x1c-this> |
|---|---|
| Date | 2012-07-31 20:07 +0000 |
| Message-ID | <50182C7D.55821.calajapr@time.synchro.net> |
| In reply to | #16852 |
To: glen herrmannsfeldt From: "xvictoryeohx" <xvictoryeohx@1:261/38.remove-dpk-this> To: glen herrmannsfeldt From: "xvictoryeohx" <xvictoryeohx@1:261/38.remove-rf4-this> To: glen herrmannsfeldt From: xvictoryeohx@gmail.com On Monday, July 30, 2012 12:31:35 PM UTC+8, glen herrmannsfeldt wrote: > xvictoryeohx@gmail.com wrote: > > > C=L(1+i/100)power of n > > > > > i am stuck here > > > for example square root is Math.sqrt(x) > > > How do i do Power of a value? > > > > Math.pow(). > > > > -- glen Thanks! -+- 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 --- 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
[toc] | [prev] | [next] | [standalone]
| From | "Roedy Green" <roedy.green@1:261/38.remove-x1c-this> |
|---|---|
| Date | 2012-07-31 20:07 +0000 |
| Message-ID | <50182C7D.55824.calajapr@time.synchro.net> |
| In reply to | #16850 |
To: xvictoryeohx From: "Roedy Green" <roedy.green@1:261/38.remove-dpk-this> To: xvictoryeohx From: "Roedy Green" <roedy.green@1:261/38.remove-rf4-this> To: xvictoryeohx From: Roedy Green <see_website@mindprod.com.invalid> On Sun, 29 Jul 2012 21:28:11 -0700 (PDT), xvictoryeohx@gmail.com wrote, quoted or indirectly quoted someone who said : >C=L(1+i/100)power of n > >i am stuck here >for example square root is Math.sqrt(x) >How do i do Power of a value? see http://mindprod.com/jgloss/power.html -- Roedy Green Canadian Mind Products http://mindprod.com The greatest shortcoming of the human race is our inability to understand the exponential function. ~ Dr. Albert A. Bartlett (born: 1923-03-21 age: 89) http://www.youtube.com/watch?v=F-QA2rkpBSY -+- 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 --- 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
[toc] | [prev] | [next] | [standalone]
| From | "Andreas Leitgeb" <andreas.leitgeb@1:261/38.remove-x1c-this> |
|---|---|
| Date | 2012-07-31 20:07 +0000 |
| Message-ID | <50182C7E.55829.calajapr@time.synchro.net> |
| In reply to | #16856 |
To: Roedy Green
From: "Andreas Leitgeb" <andreas.leitgeb@1:261/38.remove-dpk-this>
To: Roedy Green
From: "Andreas Leitgeb" <andreas.leitgeb@1:261/38.remove-rf4-this>
To: Roedy Green
From: Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at>
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%29
-+- 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
--- 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
[toc] | [prev] | [next] | [standalone]
| From | "Patricia Shanahan" <patricia.shanahan@1:261/38.remove-x1c-this> |
|---|---|
| Date | 2012-07-31 20:07 +0000 |
| Message-ID | <50182C7E.55831.calajapr@time.synchro.net> |
| In reply to | #16862 |
To: Andreas Leitgeb From: "Patricia Shanahan" <patricia.shanahan@1:261/38.remove-dpk-this> To: Andreas Leitgeb From: "Patricia Shanahan" <patricia.shanahan@1:261/38.remove-rf4-this> 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. 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 --- 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
[toc] | [prev] | [next] | [standalone]
| From | "Patricia Shanahan" <patricia.shanahan@1:261/38.remove-x1c-this> |
|---|---|
| Date | 2012-07-31 20:07 +0000 |
| Message-ID | <50182C7F.55834.calajapr@time.synchro.net> |
| In reply to | #16863 |
To: Patricia Shanahan From: "Patricia Shanahan" <patricia.shanahan@1:261/38.remove-dpk-this> To: Patricia Shanahan From: Patricia Shanahan <pats@acm.org> 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 -+- 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
[toc] | [prev] | [next] | [standalone]
| From | "glen herrmannsfeldt" <glen.herrmannsfeldt@1:261/38.remove-x1c-this> |
|---|---|
| Date | 2012-07-31 20:07 +0000 |
| Message-ID | <50182C80.55838.calajapr@time.synchro.net> |
| In reply to | #16863 |
To: Patricia Shanahan
From: "glen herrmannsfeldt" <glen.herrmannsfeldt@1:261/38.remove-dpk-this>
To: Patricia Shanahan
From: glen herrmannsfeldt <gah@ugcs.caltech.edu>
Patricia Shanahan <patricia.shanahan@1:261/38.remove-rf4-this> wrote:
(snip, someone wrote)
>> x ^ n = exp ( log(x) * n ) | x = (1 + i/100)
>> = exp ( log( 1 + i/100 ) * n)
>> = exp ( log1p ( i/100 ) * n)
(snip)
> 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?
I didn't know about the log1p function. (Does Java have one?)
As x gets small log(1+x) loses precision. Consider:
log(1+1e-60)
The x87 instruction set has an instruction for evaluating log(1+x) and one for
evaluating exp(x-1). Most HLLs don't.
-- glen
-+- 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
[toc] | [prev] | [next] | [standalone]
| From | "Patricia Shanahan" <patricia.shanahan@1:261/38.remove-x1c-this> |
|---|---|
| Date | 2012-07-31 20:07 +0000 |
| Message-ID | <50182C80.55841.calajapr@time.synchro.net> |
| In reply to | #16868 |
To: glen herrmannsfeldt From: "Patricia Shanahan" <patricia.shanahan@1:261/38.remove-dpk-this> To: glen herrmannsfeldt From: Patricia Shanahan <pats@acm.org> On 7/30/2012 3:26 PM, glen herrmannsfeldt wrote: ... > I didn't know about the log1p function. (Does Java have one?) It's in java.lang.Math, since 1.5. 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
[toc] | [prev] | [next] | [standalone]
| From | "Andreas Leitgeb" <andreas.leitgeb@1:261/38.remove-x1c-this> |
|---|---|
| Date | 2012-07-31 20:07 +0000 |
| Message-ID | <50182C81.55844.calajapr@time.synchro.net> |
| In reply to | #16868 |
To: glen herrmannsfeldt From: "Andreas Leitgeb" <andreas.leitgeb@1:261/38.remove-dpk-this> To: glen herrmannsfeldt From: Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> glen herrmannsfeldt <gah@ugcs.caltech.edu> wrote: > and one for evaluating exp(x-1). That is exp(x)-1, not exp(x-1), just for the record ;-) -+- 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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web