Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > RE: nth root

Reply
Thread Tools

RE: nth root

 
 
ajaksu
Guest
Posts: n/a
 
      01-31-2009
On Jan 31, 12:03 pm, Mark Dickinson <(E-Mail Removed)> wrote:
[...]
> t1 = timeit.Timer("x = n**power", "n = 4021503534212915433093809093996098953996019232; power = 1./13")
> t2 = timeit.Timer("x = n**power", "n = 4021503534212915433093809093996098953996019232.; power = 1./13")


And by using a float literal instead of "float
(402150353421291543309...)", (BTW, here -^), it not only is faster but
also a great way make some innocent bystander waste his eyesight
trying to figure out the magic trick
 
Reply With Quote
 
 
 
 
Mark Dickinson
Guest
Posts: n/a
 
      01-31-2009
On Jan 31, 7:04*pm, ajaksu <(E-Mail Removed)> wrote:
> also a great way make some innocent bystander waste his eyesight
> trying to figure out the magic trick


Oh, come on! At least I put the two lines next to each other!

Mark

 
Reply With Quote
 
 
 
 
Tim Roberts
Guest
Posts: n/a
 
      02-01-2009
"Tim Roberts" <(E-Mail Removed)> wrote:
>
>Thanks - you're probably right - just my intuition said to me that rather than calculating that the 13th root of 4021503534212915433093809093996098953996019232
>is 3221.2904208350265....
>there must be a quicker way of finding out its between 3221 and 3222....
>
>....but perhaps not.


Also, remember that the number you computed there is not really the 13th
root of 4021503534212915433093809093996098953996019232. When you convert
it to float to do the exponentiation, you're losing everything after the
15th significant digit. Of course, if all you're looking for is the
nearest integer, that's not very relevant.

Do you really need the absolute number? You could take log(x)/13 and work
with the log of the results. I suspect (without trying it) that's faster
than the exponentiation.

From one Tim Roberts to another.
--
Tim Roberts, http://www.velocityreviews.com/forums/(E-Mail Removed)
Providenza & Boekelheide, Inc.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
RE: nth root Tim Roberts Python 10 02-02-2009 05:49 PM
Nth Root in Ruby Peter Laurens Ruby 3 10-22-2007 05:35 PM
Calculating the nth root of a number Protoman C++ 14 09-17-2005 02:32 AM
Algorithm to find nth largest or nth smallest in a range Code4u C++ 4 07-13-2005 03:18 AM
SRT DIvision, Square root and reciprocal square root alghazo@siu.edu VHDL 0 05-27-2004 06:23 AM



Advertisments