Path: csiph.com!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail From: glen herrmannsfeldt Newsgroups: comp.lang.java.programmer Subject: Re: What is the command to do a power of a value Date: Mon, 30 Jul 2012 22:26:15 +0000 (UTC) Organization: Aioe.org NNTP Server Lines: 25 Message-ID: References: <5016CF47.55648.calajapr@time.synchro.net> <5016CF47.55649.calajapr@time.synchro.net> NNTP-Posting-Host: H0vc4U5LIRkRHNPyGCs2dA.user.speranza.aioe.org X-Complaints-To: abuse@aioe.org User-Agent: tin/1.9.6-20100522 ("Lochruan") (UNIX) (Linux/2.6.32-5-amd64 (x86_64)) X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.lang.java.programmer:16685 Patricia Shanahan 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