float("nan") in set or as key

Ethan Furman ethan at stoneleaf.us
Wed Jun 1 14:10:33 EDT 2011


Carl Banks wrote:
> For instance, say you are using an implementation that uses
 > floating point, and you define a function that uses Newton's
 > method to find a square root:
> 
> def square_root(N,x=None):
>     if x is None:
>         x = N/2
>     for i in range(100):
>         x = (x + N/x)/2
>     return x
> 
> It works pretty well on your floating-point implementation.
 > Now try running it on an implementation that uses fractions
 > by default....
> 
> (Seriously, try running this function with N as a Fraction.)

Okay, will this thing ever stop?  It's been running for 90 minutes now. 
  Is it just incredibly slow?

Any enlightenment appreciated!

~Ethan~



More information about the Python-list mailing list