code optimization (calc PI)

Gabriel Genellina gagsl-py at yahoo.com.ar
Thu Jan 4 01:52:57 CET 2007


At Wednesday 3/1/2007 12:50, mm wrote:

>Hmm... it's a question. It was not that easy to translate this #@*?%!
>C-Program into readable code and then to Python. But it works.

Because that code was written with C in mind, and uses some C 
subtlecies (uhm, got it right?) obscuring the original algorithm.
BTW, do you know where the algorithm was taken from?

>while c*2:

`while c:` does *exactly* the same without computing (and discarding) 
an intermediate object.

>     while (b-1):

If b>=1 initially (as it should, else this will be a loooooong loop), 
this is the same as `while b>1:` but without computing (and 
discarding) an intermediate object.

>        b=b-1 ## just for while-loop condition.

I'm not sure if the compiler is smart enough to translate this into `b -= 1`

>    c = c-14;  ## this is code vor the 1st while-loop, BUT bust run after

Same as above

>    pi = pi + str("%04d" % int(e + d/a))  ## this should be fast?! I dont

Someone else already pointed out how to improve this.

You don't show the rest of the code...


-- 
Gabriel Genellina
Softlab SRL 


	

	
		
__________________________________________________ 
Preguntá. Respondé. Descubrí. 
Todo lo que querías saber, y lo que ni imaginabas, 
está en Yahoo! Respuestas (Beta). 
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas 




More information about the Python-list mailing list