Re: nth root
- From: Dan Goodman <dg.gmane@xxxxxxxxxxxxxx>
- Date: Sat, 31 Jan 2009 17:48:31 +0100
Mark Dickinson wrote:
I'd also be a bit worried about accuracy. Is it important to you
that the
integer part of the result is *exactly* right, or is it okay if
(n**13)**(1./13) sometimes comes out as slightly less than n, or if
(n**13-1)**(1./13) sometimes comes out as n?
I don't think accuracy is too big a problem here actually (at least for 13th roots). I just tested it with several hundred thousand random 100 digit numbers and it never made a mistake. The precision of double ought to easily guarantee a correct result. If you let x=int(1e100**(1./13)) then ((x+1)**13-x**13)/x**13=2.6e-7 so you only need around the first 8 or 9 digits of the 100 digit number to compute the 13th root exactly (well within the accuracy of a double).
OTOH, suppose you were doing cube roots instead then you would need the first 35 digits of the 100 digit number and this is more accurate than a double. So for example int(1e100**(1./3)) is a long way from being the integer part of the true cube root (it's between 10**18 and 10**19 away).
Dan
.
- Follow-Ups:
- Re: nth root
- From: Mark Dickinson
- Re: nth root
- References:
- RE: nth root
- From: Tim Roberts
- Re: nth root
- From: Mark Dickinson
- RE: nth root
- Prev by Date: fastest way to detect a user type
- Next by Date: Re: nth root
- Previous by thread: Re: nth root
- Next by thread: Re: nth root
- Index(es):
Relevant Pages
|